This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Are private base classes really private ?
- To: David C Binderman <dcb at pncl dot co dot uk>
- Subject: Re: Are private base classes really private ?
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 24 Aug 1998 00:48:51 -0300
- Cc: egcs-bugs at cygnus dot com
- References: <199808230904.KAA26163@fm215.facility.pipex.com>
David C Binderman <dcb@pncl.co.uk> writes:
> struct A { };
> struct B : private A {};
> B b;
> A* pa = (A *) &b; // should fail here, according to 15.3.2 of Stroustrup 3.
Not according to the Standard. It says [expr.cast]:
7 In addition to those conversions, the following static_cast and rein-
terpret_cast operations (optionally followed by a const_cast opera-
tion) may be performed using the cast notation of explicit type con-
version, even if the base class type is not accessible:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--a pointer to an object of derived class type or an lvalue of derived
class type may be explicitly converted to a pointer or reference to
an unambiguous base class type, respectively;
[snip]
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil