C++ template function overload resolution bug
Oskar Enoksson
osken393@student.liu.se
Wed Nov 18 13:07:00 GMT 1998
This example from the standard compiles without even a
warning with all versions of egcs I've tried, even though
one call is ambiguous (p257 ç14.5.5.2). Maybe this should
be allowed except when compiling with --ansi --pedantic ?
// Begin example
template<class T> struct A { A(); };
template<class T> void f(T);
template<class T> void f(T*);
template<class T> void f(const T*);
template<class T> void g(T);
template<class T> void g(T&);
template<class T> void h(const T&);
template<class T> void h(A<T>&);
void m() {
const int *p;
f(p); // f(const T*) is more specialized than f(T) or f(T*)
float x;
g(x); // Ambiguous: g(T) or g(T&)
A<int> z;
h(z); // overload resolution selects h(A<T>&)
const A<int> z2;
h(z2); // h(const T&) is called because h(A<T>&) is not callable
}
// End example
*/ Oskar Enoksson, Linkoping, Sweden /*
More information about the Gcc-bugs
mailing list