https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314
kamilek1313 at poczta dot fm changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kamilek1313 at poczta dot fm
--- Comment #20 from kamilek1313 at poczta dot fm ---
I think the point of this issue was missed. It has nothing to do with
constructors/destructors, it can be reproduced with the following example:
class Grandparent {
protected:
int foo = 0;
};
struct Parent : private Grandparent {
};
struct Child : public Parent {
void bar() {foo = 1;}
};
Currently (GCC 9.2.0, also present in experimetal), the following error is
issued:
prog.cc: In member function 'void Child::bar()':
prog.cc:10:17: error: 'int Grandparent::foo' is protected within this context
10 | void bar() {foo = 1;}
| ^~~
prog.cc:3:9: note: declared protected here
3 | int foo = 0;
| ^~~
See Wandbox: https://wandbox.org/permlink/mwF205Xm6A3xcKGy
This error message is just wrong. Grandparent::foo is private within this
context, due to private inheritance. If it was protected, it would be
accessible by Child. Upon seeing this message, I have no clue what is wrong
(yeah, it is protected, so what?)
For comparison, clang 10 produces clear(ish) error message for the same code:
prog.cc:10:17: error: cannot cast 'Child' to its private base class
'Grandparent'
void bar() {foo = 1;}
^
prog.cc:6:17: note: declared private here
struct Parent : private Grandparent {
^~~~~~~~~~~~~~~~~~~
prog.cc:10:17: error: 'foo' is a private member of 'Grandparent'
void bar() {foo = 1;}
^
prog.cc:6:17: note: constrained by private inheritance here
struct Parent : private Grandparent {
^~~~~~~~~~~~~~~~~~~
prog.cc:3:9: note: member is declared here
int foo = 0;
^
2 errors generated.