The program below is expected to exit with a status of 0. Only symbols from the definition context are to be considered during unqualified lookup (bullet 1), and only symbols defined in associated namespaces in both the definition and instantiation context are to be considered during Koenig lookup (bullet 2). When compiled with gcc 3.2, the program returns 1 instead, indicating that gcc fails to correctly implement 14.6.4.2, p1, bullet 1 in that it considers symbols outside the definition context of N::bar during unqualified lookup. EDG eccp -A (i.e., strict mode) implements the rules correctly. For a discussion of the rules see the email thread at c++std-core@research.att.com starting with c++std-core-10009. $ cat t.cpp; g++ -static t.cpp && ./a.out ; echo $? namespace N { template <class T> T foo (T) { return T (); } template <class T> T bar (T t) { return foo (t); } } struct S { S (int i = 0): i_ (i) { } int i_; }; namespace N { /* template <> */ S foo (S) { return S (1); } } int main () { return 1 == N::bar (S ()).i_; } 1
Confirmed. In other words, GCC incorrectly picks the second N::foo() because it lookups all the functions available at the point of call, while it should only use the definition context to lookup the function names for unqualified lookup. This would make it call the first N::foo().
This is another dup of bug 2922. *** This bug has been marked as a duplicate of 2922 ***