Commit Message

-Wnon-virtual-dtor isn't always what you want, defining a polymorphic
object without a virtual destructor is not necessarily a mistake. You
may never delete such an object so instead of warning when the class
is defined it's more useful to warn only when the class is deleted, as
Clang does with -Wdelete-non-virtual-dtor
This patch implements the same warning for G++.
Unlike Clang's, this diagnostic distinguishes the case where the
pointer might refer to a base class from the case where it definitely
does because the static type is abstract. There's no warning for a
C++0x final class, since the pointer must refer to the most-derived
type. I'm not entirely happy with the diagnostic text as I don't
think we usually refer to undefined behaviour. Better suggestions
welcome.
The new test uses -std=gnu++0x in order to test a 'final' class,
should that be split into a separate c++0x test, so the rest uses
gnu++98?
I'm not sure why PR c++/7302 is still open, but I think this would
allow it to be closed, as it issues a warning for the delete
expression in comment 25.
Bootstrapped and tested x86_64-linux
OK for trunk?
c-family/ChangeLog:
* c.opt: Add -Wdelete-non-virtual-dtor.
* c-opts.c (c_common_handle_option): Include it in -Wall.
cp/ChangeLog:
* init.c (build_delete): Warn when deleting type with non-virtual
destructor.
testsuite/ChangeLog:
* testsuite/g++.dg/warn/delete-non-virtual-dtor.cc: New.
ChangeLog:
* doc/invoke.texi: Document -Wdelete-non-virtual-dtor.