From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4232 invoked by alias); 4 Jun 2007 12:01:35 -0000 Received: (qmail 4204 invoked by uid 48); 4 Jun 2007 12:01:23 -0000 Date: Mon, 04 Jun 2007 12:01:00 -0000 Subject: [Bug c++/32204] New: friend from global namespace in template class ignored Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "klaus dot kretschel at dlr dot de" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-06/txt/msg00191.txt.bz2 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&); template < class PIX > class A::B { friend void ::f(A::B&); PIX z; }; void f(A::B& i) { int a = i.z; } int main() { A::B 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&); } template < class PIX > class A::B { friend void C::f(A::B&); PIX z; }; void C::f(A::B& i) { int a = i.z; } int main() { A::B 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