Topic: apparently trivial template overloading


Author: sebor@my-deja.com
Date: 1999/12/11
Raw View
Hi,

can someone kindly explain or point to the appropriate section in the
standard that describes whether the code below is ambiguous in any of
the combinations of CONST and VAR and why, i.e., whether and why it is
ambiguous when compiled like so:

$ CC                        t.cc   # case 1
$ CC -DCONST=const          t.cc   # case 2
$ CC               -DVAR=ia t.cc   # case 3
$ CC -DCONST=const -DVAR=ia t.cc   # case 4

The 6 unnamed recent industry-strength compilers I've tried this with
all give different results (summarized in table below).

Thanks
Martin


#ifndef CONST
#define CONST
#endif

#ifndef VAR
#define VAR "x"
#endif

template <class T>
int foo (CONST T*) { return 0; }

template <class T>
int foo (CONST T&) { return 1; }

int main () {
    int ia [2];
    return foo (VAR);
}


+---+-----+-----+---+---+---+---+---+---+
|   | options   |      compiler         |
+---+-----+-----+---+---+---+---+---+---+
| # |CONST| VAR | A | E | G | I | M | S |
+---+-----+-----+---+---+---+---+---+---+
| 1 |     | "x" | 0 | 0 | - | - | - | - |
+---+-----+-----+---+---+---+---+---+---+
| 2 |const| "x" | 0 | - | - | - | - | - |
+---+-----+-----+---+---+---+---+---+---+
| 3 |     |  ia | 1 | 0 | - | - | - | - |
+---+-----+-----+---+---+---+---+---+---+
| 4 |const|  ia | 1 | - | 1 | - | - | 1 |
+---+-----+-----+---+---+---+---+---+---+

0 - program compiles and returns 0 when run
1 - program compiles and returns 1 when run
- - program generates an ambiguity error


Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]