This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++-3.1: dependent name ADL handled incorrectly?
- From: Markus Werle <numerical dot simulation at web dot de>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 26 Jul 2002 12:09:08 +0200
- Subject: c++-3.1: dependent name ADL handled incorrectly?
Hi!
On comp.lang.c++.moderated there is a rather hot discussion
on argument dependant lookup rules.
See thread "Understanding Koenig lookup".
Daveed Vandevoorde <google@vandevoorde.com> posted the
following piece of code to test compilers
---------------------------
// Classic
namespace N {
struct S {};
S operator+(S const&, S const&) { return S(); }
}
void f1(N::S const &s) {
s+s; // If this compiles, your compiler probably
} // supports "class Koenig lookup"
// Nondependent ADL
namespace N {
void g(S const&) {}
}
void f2(N::S const &s) {
g(s); // If this compiles, your compiler probably
} // support nondependent ADL (extended Koenig
// lookup).
// Dependent ADL
void g1(float) {}
template<typename T> void f3(T a) {
g1(a);
}
void g1(double) {}
int main() {
f3(9); // If this compiles, your compiler probably
return 0; // implements dependent name ADL correctly.
}
----------------
Though I like the way gcc handles this situation it seems not to be
ANSI-compliant.:
> g++ ~/hp-home/C++/EXPERIMENTAL/ADL_Pitfall.2.C && a.out
/home/markus/hp-home/C++/EXPERIMENTAL/ADL_Pitfall.2.C: In function `void f3(T)
[with T = int]':
/home/markus/hp-home/C++/EXPERIMENTAL/ADL_Pitfall.2.C:27: instantiated from here
/home/markus/hp-home/C++/EXPERIMENTAL/ADL_Pitfall.2.C:22: call of overloaded `
g1(int&)' is ambiguous
/home/markus/hp-home/C++/EXPERIMENTAL/ADL_Pitfall.2.C:20: candidates are: void
g1(float)
/home/markus/hp-home/C++/EXPERIMENTAL/ADL_Pitfall.2.C:25: void
g1(double)
> g++ -v
Reading specs from /opt/gcc-3.1/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs
Configured with: ../gcc-3.1/configure --prefix=/opt/gcc-3.1 --enable-shared --with-gnu-as --with-as=/opt/gcc-3.1/bin/as --with-gnu-ld
--with-ld=/opt/gcc-3.1/bin/ld --enable-version-specific-runtime-libs --enable-languages=c,c++,f77
Thread model: single
gcc version 3.1
best regards,
Markus