Tested with g++ versions 4.1.2 and 4.3.2, they both fail to reject the following invalid code:
class E { int x; class B { }; class I { B b; // error: E::B is private int y; void f(E* p, int i) { p->x = i; // error: E::x is private } }; int g(I* p) { //return p->y; // error: I::y is private (g++ correctly errors here) } }; This is taken straight from the standard, section 11.8.1: http://www.csci.csusb.edu/dick/c++std/cd2/access.html 1 The members of a nested class have no special access to members of an enclosing class, nor to classes or functions that have granted friend- ship to an enclosing class; the usual access rules (_class.access_) shall be obeyed. The members of an enclosing class have no special access to members of a nested class; the usual access rules (_class.access_) shall be obeyed. [Example: class E { int x; class B { }; class I { B b; // error: E::B is private int y; void f(E* p, int i) { p->x = i; // error: E::x is private } }; int g(I* p) { return p->y; // error: I::y is private } }; --end example] -- Summary: Invalid access with nested classes Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: grogers at tecore dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38255