The following code shouldn't compile; yet gcc accepts it: template <typename T> int Foo() { return Bar(T()); }
int x = Foo<bool>(); // This shouldn't compile. int Bar(bool x) { return 0; } The problem is that when Foo<bool>() is instantiated, the compiler should search for Bar() only at the template definition site, not at the point of instantiation, since bool is not a class type and ADL doesn't apply. Similarly, this shouldn't compile either, but gcc also accepts it: template <typename T> int Foo() { return Bar(T()); } int Bar(bool x) { return 0; } int x = Foo<bool>(); // This shouldn't compile. Note that both clang and Comeau reject the code correctly. This is related to bug 42291 - I don't know if they are caused by exactly the same thing though. -- Summary: gcc should reject code violating the two-phase look-up rules (related to bug 42291) Product: gcc Version: 4.2.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: wan at google dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42292