a barely useful option?

Sol Foster colomon@ralf.org
Mon Aug 9 12:26:00 GMT 1999


Joe Buck writes:
> If the implementation were effortless, the warning could be put in but
> modified to behave as follows: OK, so the base class has a non-virtual
> destructor.  Consider this code:
>
> 	Base* b = new Derived(constructor-args);
> 	....
> 	delete b;
>
> will the right thing happen?  Well, if Derived has no additional data
> members and does not declare a destructor, the right thing does happen, so
> the compiler should never issue a warning in such a case.

My understanding is that doing this results in undefined behavior
according to the standard.  I can't cite the standard on this, alas, but
the C++ FAQ claims that a virtual destructor *is* required if the base
class destructor is non-trivial.

It may work in GCC, but there are no guarantees in other compilers, and
so it is exactly the sort of thing one would like to be warned about.

--
Sol Foster: colomon@ralf.org
HarmonyWare, Inc: http://www.harmonyware.com



More information about the Gcc mailing list