This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: a barely useful option?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]