http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46075
Summary: g++ wrongly lookups builtin types in ADL (compiles wrong code) Product: gcc Version: 4.4.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: sly...@inbox.ru clang++ and comeau don't compile following code: inst.cc:17:9: error: use of undeclared identifier 'my_foo' my_foo ((const T *)0); ^ inst.cc:36:7: note: in instantiation of member function 'my_T<char>::my_T' requested here User::User() { } ^ 1 error generated. // ------------------ inst.cc --------------------------------- // http://blog.llvm.org/2009/12/dreaded-two-phase-name-lookup.html // should fail // 23:01:10 < dgregor> slyfox_: Clang is correct // 23:01:39 < slyfox_> dgregor: how can i make this code compile with clang w/o moving declaration upper? // 23:02:49 < dgregor> you'll need to move the declaration up, or instantiate my_T with a non-builtin type (so that // argument-dependent lookup can find my_foo in the namespace of that type) // 23:03:27 < slyfox_> so builtin types are special // 23:04:02 < dgregor> not special, really; they have no "associated namespaces", i.e., there's nowhere for the compiler to l ook // at instantiation time template<typename T> struct my_T { my_T() { // this one explicitely mentions 'T' as one of params my_foo ((const T *)0); // this one would be 'T' independent, and gcc will report // an error it i'll try to use this one instead. //my_foo((const T *)0); } }; struct User { User(); // explicit c-tor my_T<char> t; }; // we specialize my_foo for 'const char *' static void my_foo (const char *) {} // To be checked. Should work too //static void my_foo(const void *) {} User::User() { } int main() { User u; return 0; }