https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118218
Bug ID: 118218 Summary: GCC allows the instantiation of private nested classes in a base class from a derived class in a multi-level inheritance chain Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wangbopku15 at gmail dot com Target Milestone: --- Consider the following code: ~~~~~~~~~~~~~~~~~~~~~~~~~~~ struct B { struct X {}; }; class C: private B{}; struct D : private C{ struct X x; }; int main(){ D d; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~ It seems that struct 'X' should be invisible within struct 'D', as class 'C' private inherits 'B', which makes 'C::X' private. GCC accepts the code but MSVC, EDG and clang all reject it, with error messages like: ~~~~~~~~~~~~~~~~~~~~~~~~~~~ <source>:7:10: error: 'X' is a private member of 'B' 7 | struct X x; | ^ <source>:5:11: note: constrained by implicitly private inheritance here 5 | class C : B{}; | ^ <source>:2:10: note: member is declared here 2 | struct X {}; | ^ 1 error generated. ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Please see https://godbolt.org/z/Eq5xnzd9o