As described in ISO C++ 2003
§11.8 Nested classes [class.access.nest]
The members of a nested class have no special access to members of an enclosing class, nor to classes or functions that have granted friendship to an enclosing class; the usual access rules (clause 11) shall be obeyed. The members of an enclosing class have no special access to members of a nested class; the usual access rules (clause 11) shall be obeyed.
[Example:
class E { int x; class B { }; class I { B b; // error: E::B is private ERROR 1 int y; void f(E* p, int i) { p->x = i; // error: E::x is private ERROR 2 } }; int g(I* p) { //return p->y; // error: I::y is private ERROR 3 } }; int main() {}
—end example]
So I think that clang and g++ are wrong as they compile this code successfully.
Or do I understand something wrong?