http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53596

             Bug #: 53596
           Summary: g++-4.7 -Wall shouldn't complain for non-virtual
                    protected dtor
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: kim.wali...@gmail.com


Created attachment 27569
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27569
g++-4.7 -Wall produces erronous [-Wdelete-non-virtual-dtor] warning

g++-4.7 shouldn't complain for non-virtual protected dtor if the base class has
virtual functions. Previous versions of g++ do not warn, other compilers (msvc
/W4, sunCC +w2) do not warn.

terminal log:

[walki@walki Desktop]$ g++-4.7 -Wall test.cpp 
test.cpp: In function ‘int main()’:
test.cpp:19:10: warning: deleting object of polymorphic class type ‘Derived’
which has non-virtual destructor might cause undefined behaviour
[-Wdelete-non-virtual-dtor]

/////////////////////////////////////////////////////////////////////////
// file: test.cpp

#include <iostream>

class Base {
public:
  virtual void foo() = 0;
protected:
  ~Base() { } // legal C++ code
};

class Derived : public Base {
public:
  virtual void foo() { std::cout << "Derived::foo()"      << std::endl; }
  ~Derived()         { std::cout << "Derived::~Derived()" << std::endl; }
};

int main() {
  Derived* derived = new Derived();
  derived->foo();
  delete derived; // legal, there must be no warning!
  return 0;
}

/////////////////////////////////////////////////////////////////////////

Reply via email to