X-Bugzilla-Reason: CC First: I apologize if this report is missing something but I did not find enough information in the guidelines to be more accurate. Furthermore, I have only gcc 4.1.2 prerelease available (from Suse Linux 10.2), so I will be glad if somebody tells me the bug has been fixed in a later version.
The bug is related to 8355 and 9230, but I guess it's different. The following program does not compile; depending on the kind of invocation of 'f' 3 different errors occur (where the messages of 1 and 3 contradict to each other, see below): namespace A { template < class PIX > class B; } void f(A::B<int>&); template < class PIX > class A::B { friend void ::f(A::B<int>&); PIX z; }; void f(A::B<int>& i) { int a = i.z; } int main() { A::B<int> b; f(b); // 1. error: f is ambiguous (no, there is no 2nd declaration!) ::f(b); // 2. error: z is private (yes, but 'f' is a friend) A::f(b); // 3. error: f is not a member of A (of course) } The only invocation that should yield an error is no. 3. No. 2 should definitely work, and I guess the double colon for the global namespace should be unnecessary anywhere. No error occurs if I transfer 'f' from the global namespace to another one (C): namespace A { template < class PIX > class B; } namespace C { void f(A::B<int>&); } template < class PIX > class A::B { friend void C::f(A::B<int>&); PIX z; }; void C::f(A::B<int>& i) { int a = i.z; } int main() { A::B<int> b; C::f(b); // OK using namespace C; f(b); // OK } Another work-around is to make 'f' an template function. -- Summary: friend from global namespace in template class ignored Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: klaus dot kretschel at dlr dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32204