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: "dpiepgrass at mentoreng dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 26 Mar 2012 21:20:11 +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
David Piepgrass <dpiepgrass at mentoreng dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dpiepgrass at mentoreng dot
| |com
--- Comment #3 from David Piepgrass <dpiepgrass at mentoreng dot com> 2012-03-26 21:20:11 UTC ---
I have run into this bug or a similar bug while porting my code from MSVC to
GCC. I need to declare that a class in the global namespace is a friend of my
template class. However, I discovered that the bug still occurs if no templates
are involved. Here's my repro:
class Friend;
namespace Foo
{
class Base {
};
class Derived : protected Base {
friend class Friend;
};
}
class Friend {
void F(const Foo::Derived* data) const
{
// error: 'Foo::Base' is an inaccessible base of 'Foo::Derived'
const Foo::Base* dataB = data;
}
};
The problem disappears if either (A) Derived is not in a namespace, or (B)
Friend is in a namespace (the forward declaration of Friend is required and, of
course, must be put in the namespace too).