https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123228
Bug ID: 123228
Summary: Member is inaccessible despite friend declaration
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: arseny.orlow at yandex dot ru
Target Milestone: ---
Created attachment 63101
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63101&action=edit
Example as a file
struct A {
friend struct C;
private:
int i = 0;
};
struct B : protected A {
};
struct C : B {
void f() {
i = 1;
}
};
int main() {
C c;
c.f();
}
With
g++ -Wall -Wextra -fno-strict-aliasing -fwrapv
for all versions from 11.1 to 15.2.1 and also in the current trunk compilation
fails with error:
<source>: In member function 'void C::f()':
<source>:12:9: error: 'int A::i' is private within this context
12 | i = 1;
| ^
<source>:4:9: note: declared private here
4 | int i = 0;
| ^
On godbolt: https://godbolt.org/z/oqTfs7fnT
This error occurs both with x86-64 and arm targets. Compilation with assertions
enabled does not fail.
As far as I'm concerned, according to the standard this example should be
valid: https://eel.is/c++draft/class.access.base#5.5
Changing inheritance access specifier of B from A from protected to public
resolves the error.