This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c++/49605] New: -Wdelete-non-virtual-dtor is not picky enough


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


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