The following code is compiled with gcc (Gentoo 4.4.3 p1.0) 4.4.3 g++ -std=c++0x -Wall x.cpp but the output of executing a.out is *** glibc detected *** ./a.out: free(): invalid pointer: 0x083b4010 *** Aborted
class Dummy { public: Dummy() { } ~Dummy() { } }; class BaseA { public: inline BaseA() = default; virtual ~BaseA() = default; private: Dummy dummy; }; class BaseB { public: inline BaseB() = default; virtual ~BaseB() = default; }; class Foo : public BaseA, public BaseB { public: inline Foo() = default; virtual ~Foo() = default; }; int main() { BaseB *baseB = new Foo(); delete baseB; return 0; } by changing the dtor of BaseB from virtual ~BaseB() = default; to virtual ~BaseB() {} the program runs correctly (and adding cout in the dtor of Dummy shows the dtor of Dummy is called as expected) I suppose "= default" together with the fact that there is nothing to do in the dtor of BaseB misleads g++ to generate incorrect code. By adding a member (e.g. Dummy dummy) in the BaseB just like in the BaseA (and leave the "= default" not modified) , g++ generates the correct code, both dtors of Dummy are called as expected. -- Summary: Incorrect delete via a base pointer Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Etrnls at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43100