Question

class A {
    public:
            int a;
};

class B: private A {
};

class C: public A {
};

class D: public B, public C {
        D() {
                B::a = 0;
        }
};

This compiles even though B privately inherits A. If I remove D's inheritance of C, the compiler says a is inaccessible, like I'd expect. So is the inheritance of C confusing my compiler?

Compiler is gcc 4.4.7

Was it helpful?

Solution

Looks like a genuine compiler bug, as the standard does not allow such access in

11.2 Accessibility of base classes and base class members

Looking for evidence outside the standard itself, WhozCraig already brought up that clang does not allow such access.

Looking for similar patterns which might be confused in gcc, there is diamon-inheritance with virtual base class A, which would have allowed such access, as the path of most access determines what protections apply.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top