This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
non-virtual + virtual inheritance bug
- From: "Stuart Brooks" <stuartb at cat dot co dot za>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 21 Feb 2005 10:23:38 +0200
- Subject: non-virtual + virtual inheritance bug
- Organization: Intervid Technologies
- References: <BAY10-F28DA6663E18CEED1FF8FCA76E0@phx.gbl>
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