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.
On Fri, 04 Mar 2005 19:15:41 -0600 (CST), Chris Lattner <sabre@nondot.org> said:
> It's not a matter of warning vs not warning: it's a matter of
> emitting bogus warnings *sometimes* when you can emit the proper
> warning *all of the time*.
I don't think you can emit the proper warning all of the time on
destruction, either:
void deleteB( B *obj ) {
delete obj;
}
If B is a base class with a non-virtual destructor, then this is safe
if obj's dynamic type is B, unsafe otherwise. The compiler can't tell
if the programmer has some sort of implicit contract about what the
dynamic type of objects passed to deleteB will be.
(Personally, I would vote for keeping the warning as-is, though I
don't think my statements above are a strong argument for not moving
it.)
David Carlton
david.carlton@sun.com