Private base class and multiple inheritance

c++

Solution

This is most certainly a bug. There is no reason why inheriting from class `B` as well should change the accessibility of `C`'s members.

Not even GCC 4.8.0 (beta) seems to have solved this problem. Clang 3.2 and ICC 13.0.1, on the other hand, correctly refuse to compile this code.

Problem

Consider : ``` struct A { int x;}; struct B : A {}; struct C : private A {}; ``` Now, as expected, the code ``` struct D : C { D () { C::x = 2; } }; int main () { D d; } ``` does not compile: ``` test2.cc: In constructor ‘D::D()’: test2.cc:1:16: error: ‘int A::x’ is inaccessible test2.cc:7:12: error: within this context ``` Now, if I do ``` struct D : B, C { D () { C::x = 2; } }; int main () { D d; } ``` then the error disappear! Isn't `A::x` supposed to be inaccessible too? What is the explanation here? I'm using `gcc version 4.7.2 (GCC)`, linux x86_64, if this matters. EDIT: It does not compile with Clang 3.2: clang 3.2 But it does with gcc 4.7.2: gcc 4.7.2

Original source

Related problems