https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119448
Bug ID: 119448
Summary: Private base class name of base class seems should be
inaccessible in friend class declaration in its
derived class
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rush102333 at gmail dot com
Target Milestone: ---
Consider:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
struct payload {};
struct base: private payload {
};
struct derived: base {
friend class payload;
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
https://godbolt.org/z/KadzWvMTK
The above code is currently rejected by clang and EDG, while accepted by gcc
and MSVC.
The diagnostic of clang:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:7:18: error: 'payload' is a private member of 'payload'
7 | friend class payload;
| ^
<source>:3:14: note: constrained by private inheritance here
3 | struct base: private payload {
| ^~~~~~~~~~~~~~~
<source>:1:8: note: member is declared here
1 | struct payload {};
| ^
1 error generated.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
See discussion on llvm bug tracker:
https://github.com/llvm/llvm-project/issues/121258