Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple inheritance makes private member accessible

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

like image 702
chuck1 Avatar asked Apr 11 '14 23:04

chuck1


1 Answers

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.

like image 69
Deduplicator Avatar answered Nov 10 '22 05:11

Deduplicator