From Bugzilla Helper: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.5) Gecko/20011012 Description of problem: The attached C++ program does not compile with g++ 2.96-99 with a bogus "`class A' is inaccessible" error. egcs-1.1.2 and gcc-2.95.3 are okey. This problem is present in OpenSP (from OpenJade: openjade.sourceforge.net). Version-Release number of selected component (if applicable): How reproducible: Always Steps to Reproduce: Do this: [olchansk@sam g++-opensp]$ cat test.cc #include <stdio.h> class A { public: int aaa; }; class B: private A { public: int bbb; }; class C: public B { public: A ccc; }; [olchansk@sam g++-opensp]$ g++ -c test.cc test.cc:4: `class A' is inaccessible test.cc:18: within this context [olchansk@sam g++-opensp]$ g++ -v Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-99) [olchansk@sam g++-opensp]$ Expected Results: The fact that class A is present somewhere in the inheritance tree should not affect normal use of class A (i.e. as a class member). These compilers produce expected results (no compilation error): egcs-1.1.2 (redhat-6.2), gcc-2.95.3 and SGI CC (MIPSpro Compilers: Version 7.3.1.1m). These compilers produce an error: - gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-99) - gcc version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3) Additional info: If this is actually a bug (and not a language feature), and if it is present in gcc-3.1, please file a GCC PR- I am not familiar enough with the GCC PR system...
g++ 3.0 and 3.1 behave the same, and no, this is not a compiler bug. The inheritance brings A into class C scope as private. If you want to access A in C, you should use ::A instead (provided it is in the global namespace, otherwise the_namespace::A).