This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: a barely useful option?
- To: gcc at gcc dot gnu dot org
- Subject: Re: a barely useful option?
- From: Sol Foster <colomon at ralf dot org>
- Date: Mon, 09 Aug 1999 15:26:34 -0400
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