This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Question w.r.t. `'class Foo' has virtual functions butnon-virtualdestructor` warning.
- From: Chris Lattner <sabre at nondot dot org>
- To: Karel Gardas <kgardas at objectsecurity dot com>
- Cc: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>, gcc at gcc dot gnu dot org
- Date: Fri, 4 Mar 2005 14:45:46 -0600 (CST)
- Subject: Re: Question w.r.t. `'class Foo' has virtual functions butnon-virtualdestructor` warning.
Karel Gardas wrote:
Yes, that's undefined, but I just define this class to be able to do:
Foo* f = dynamic_cast<Foo*>(x);
l = f->iiop_version();
there is nothing like delete involved. Anyway, I agree with you that
emit warning about this is probably the right thing to do and so I will
fix my code.
I've run into this warning with C++ code as well, and it is quite
annoying. There are lots of possible reasons to want to do this sort of
thing, and adding a virtual dtor increases the size of the vtable for the
class.
It seems that the warning could be improved to be emitted when the
*delete* is seen of a class without a virtual dtor (but that does have
virtual methods). If you never actually do the questionable behavior,
you'd never get the warning. It seems like a bug to emit it for the class
definition.
-Chris
--
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/