This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49605] New: -Wdelete-non-virtual-dtor is not picky enough
- From: "miles at gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 1 Jul 2011 09:09:39 +0000
- Subject: [Bug c++/49605] New: -Wdelete-non-virtual-dtor is not picky enough
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: miles@gnu.org
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