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: "scottbaldwin at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 27 Oct 2012 08:11:45 +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
etherice <scottbaldwin at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |scottbaldwin at gmail dot
| |com
--- Comment #7 from etherice <scottbaldwin at gmail dot com> 2012-10-27 08:11:45 UTC ---
As Jonathan explains in comment #5, gcc is right to reject this code and MSVC
is wrong to accept it. You will have to add a forward declaration of the
class/function in order to declare it as a friend in the namespaced class. For
example:
// on gcc 4.7.0 (linux), these forward declarations are required for the friend
declarations in ns::NamespacedClass
class GlobalClass;
void globalFunction();
namespace ns {
struct NamespacedClass {
friend ::GlobalClass; // same result whether '::' or 'class' is part of
declaration
friend void ::globalFunction();
private:
NamespacedClass() {}
};
}
struct GlobalClass {
GlobalClass() { ns::NamespacedClass foo; }
};
void globalFunction() {
ns::NamespacedClass foo;
}