http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49605
Summary: -Wdelete-non-virtual-dtor is not picky enough
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
In the following program:
struct X
{
~X ();
virtual void meth ();
};
void d ()
{
X x;
}
"g++-snapshot -c -O2 -Wall nvdtor.cc" yields a warning:
nvdtor.cc: In function 'void d()':
nvdtor.cc:9:5: warning: deleting object of polymorphic class type 'X' which has
non-virtual destructor might cause undefined behaviour
[-Wdelete-non-virtual-dtor]
But it looks to me like the behavior in this case isn't undefined at all -- the
object being destroyed is stack-allocated, so gcc knows exactly what the actual
object type is; it's not possible for it to be a subclass of X.
Thanks,
-miles