This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
- From: "gdr at integrable-solutions dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 May 2004 23:38:16 -0000
- Subject: [Bug c++/15531] dynamic_cast fails (at runtime) when dependant on friendship of invoker
- References: <20040518232016.15531.gccbugs@contacts.eelis.net>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From gdr at integrable-solutions dot net 2004-05-18 23:38 -------
Subject: Re: New: dynamic_cast fails (at runtime) when dependant on friendship of invoker
"gccbugs at contacts dot eelis dot net" <gcc-bugzilla@gcc.gnu.org> writes:
| Consider the following snippet:
|
| struct Base
| {
| virtual ~Base () {}
| };
|
| class Derived : Base
| {
| friend int main ();
| };
|
| #include <cassert>
|
| int main ()
| {
| Base * p = new Derived;
|
| assert(dynamic_cast<Derived *>(p)); // fails
As required by the C++ standard. There is no way you can successfully
dynamic_cast from base class to derived class that does not publically
inherit.
| }
|
| When Derived is changed to publically inherit Base, the dynamic_cast succeeds.
Yes, that is what is required by the ISO C++ standard.
The PR is invalid.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15531