http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50344
Bug #: 50344 Summary: friend declaration confused by const qualifier Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: r...@gcc.gnu.org CC: ja...@gcc.gnu.org template <typename T> class C { friend T; int i; }; struct S { int f() { C<const S> c; return c.i; } }; This is valid C++11, but fails with: ac.cc: In member function 'int S::f()': ac.cc:4:8: error: 'int C<const S>::i' is private ac.cc:12:17: error: within this context The problem is that the friend declaration names "const S" so S is not considered a friend, it works if C<S> is used. The standard says "If the type specifier in a friend declaration designates a (possibly cv-qualified) class type, that class is declared as a friend" This bug predates the implementation of the C++0x extended friend rules, as shown by this example using a non-standard friend declaration supported by G++: template<typename T> struct identity { typedef T type; }; template <typename T> class C { friend class identity<T>::type; int i; }; struct S { int f() { C<const S> c; return c.i; } }; This works with all versions of G++ is C<S> is used, but not C<const S>