http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32204
jag-gnu at jag dot dreamhost.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jag-gnu at jag dot | |dreamhost.com --- Comment #2 from jag-gnu at jag dot dreamhost.com 2011-01-17 05:37:59 UTC --- Output of running a recent g++ on the code in comment 0 with cases 2 and 3 commented out: bug.cpp: In function ‘void f(A::B<int>&)’: bug.cpp:7: error: ‘int A::B<int>::z’ is private bug.cpp:10: error: within this context bug.cpp: In function ‘int main()’: bug.cpp:14: error: call of overloaded ‘f(A::B<int>&)’ is ambiguous bug.cpp:10: note: candidates are: void f(A::B<int>&) bug.cpp:6: note: void A::f(A::B<int>&) Which clearly shows the compiler thinks there is an A::f, even though case 3 says there isn't. I suspect the code below has the same problem: //namespace M { // 1 template <class T> T* makeT() { return new T; } //} namespace N { class Foo { template <class T> friend T* /*M*/::makeT(); //friend Foo* ::makeT<>(); // 2 Foo() {} }; } int main(void) { /*M*/::makeT<N::Foo>(); } bug.cpp: In function ‘T* makeT() [with T = N::Foo]’: bug.cpp:14: instantiated from here bug.cpp:9: error: ‘N::Foo::Foo()’ is private bug.cpp:2: error: within this context Either 1) putting makeT in a class or namespace, or 2) specializing makeT on Foo works around the problem.