non-virtual + virtual inheritance bug

Stuart Brooks stuartb@cat.co.za
Mon Feb 21 19:46:00 GMT 2005


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
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testprog.cpp
Type: application/octet-stream
Size: 596 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20050221/a5cf4d65/attachment-0001.obj>


More information about the Gcc-help mailing list