Nested Class Member Access
Steven L. Zook
SLZook@Qualstar.com
Thu Sep 2 19:13:00 GMT 2004
I'm using gcc 3.4.1 (I've also tried it with 3.3.1) m68k-elf and the following test file:
class cOuter { private: int Variable;
public: class cInner { public: int Function( cOuter * pOuter ); };
};
int cOuter::cInner::Function( cOuter * pOuter ) { return pOuter->Variable; }
This fragment compiles without complaint, the produced code looks good.
According to ISO/IEC 14882-2003 (is this the correct standard for GCC?) 11.8.1 [class.access.nest], I believe this should be an error. The paragraph says that nested classes have no special access rights to enclosing class members. Since cOuter::Variable is private, cOuter::cInner::Function should not have access to it.
I've searched bugzilla and found a couple of bugs posted against java for similar cases as well as #13495 (which may be related but whose example is rather obfuscated by templates).
Any C++ language lawyer comment would be appreciated. I will post a bug report if any GCC legal staff ;-) agrees that this is in violation.
More information about the Gcc
mailing list