Question w.r.t. `'class Foo' has virtual functions but non-virtualdestructor` warning.

David Carlton david.carlton@sun.com
Sat Mar 5 02:08:00 GMT 2005


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



More information about the Gcc mailing list