This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Here is the file which can be compiled to generate the bug...
----- Original Message -----
From: "Stuart Brooks" <stuartb@cat.co.za>
To: <gcc-help@gcc.gnu.org>
Sent: Monday, February 21, 2005 10:23 AM
Subject: non-virtual + virtual inheritance bug
> I have found what I believe to be a bug in g++ 2.91.60 on NetBSD 1.4.1. It
> appears to have been solved in g++ 3.3.3 which is the other version I am
> using. I was wondering if this is a known problem - a google search
> revealed a few posts around this topic but nothing which matched exactly:
>
> Basically a combination of non-virtual and virtual inheritance is
resulting
> in some funnies and ultimately a segmentation fault. I have narrowed it
down
> to the following case :
>
> >>>
> class B; // non-virtual base
> class V; // virtual base
>
> class Base: public B, public V;
> class Child: public Base;
>
> Base* b=new Child();
> Child* c=dynamic_cast<Base*>(b);
> passInAsBase(c);
>
> void passInAsBase(Base* b)
> {
> Child* c=dynamic_cast<Child*>(b);
> }
> >>>
>
> This compiles fine but causes problems when it runs (I have attached a
short
> compileable source file), in particular the dynamic cast in passInAsBase
> segmentation faults the program. If I declare Base as follows... (virtual
> class inherited first)
> class Base: public V, public B;
> ... the problem goes away. As I mentioned this all works in 3.3.3. but
> unfortunately I am tied to using my existing OS/compiler for historical
> reasons.
>
> Any pointers would be appreciated...
>
> Thanks
> Stuart
>
>
>
Attachment:
testprog.cpp
Description: Binary data
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |