This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118c. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-10-11
Consider the following example:
struct B { void f(){} };
class N : protected B { };
struct P: N { friend int main(); };
int main() {
N n;
B& b = n; // R
b.f();
}
This code is rendered well-formed by bullet 3 of 11.8.3 [class.access.base] paragraph 4, which says that a base class B of N is accessible at R if
R occurs in a member or friend of a class P derived from N, and an invented public member of B would be a private or protected member of P
This provision circumvents the additional restrictions on access to protected members found in 11.8.5 [class.protected] — main() could not call B::f() directly because the reference is not via an object of the class through which access is obtained. What is the purpose of this rule?
Rationale (April, 2010):
This is a duplicate of issue 472.