public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32204] New: friend from global namespace in template class ignored
@ 2007-06-04 12:01 klaus dot kretschel at dlr dot de
2009-12-08 23:11 ` [Bug c++/32204] " redi at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: klaus dot kretschel at dlr dot de @ 2007-06-04 12:01 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-12-08 23:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-04 12:01 [Bug c++/32204] New: friend from global namespace in template class ignored klaus dot kretschel at dlr dot de
2009-12-08 23:11 ` [Bug c++/32204] " redi at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).