This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: egcs-980517 bug report
Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de> writes:
>> class B { protected: B() { } };
>> class D : public B { void f(); };
>> void D::f() { B b; } // error
> Could you be more specific as to why this is ill-formed?
Section 11.5 [class.protected] states:
1 When a friend or a member function of a derived class references a
protected nonstatic member of a base class, an access check applies in
addition to those described earlier in clause _class.access_.4) Except
when forming a pointer to member (_expr.unary.op_), the access must be
through a pointer to, reference to, or object of the derived class
itself (or any class derived from that class) (_expr.ref_).
Since `b' is not an instance of class D, the implicit invocation of
B::B() does not take an instance of D as its implicit `this' argument,
hence it is ill-formed.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil