This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/32204] friend from global namespace in template class ignored
- From: "jag-gnu at jag dot dreamhost.com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 17 Jan 2011 05:38:17 +0000
- Subject: [Bug c++/32204] friend from global namespace in template class ignored
- Auto-submitted: auto-generated
- References: <bug-32204-4@http.gcc.gnu.org/bugzilla/>
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.