[cfe-dev] operator delete[] does not call derived class destructor
bd satish
bdsatish at gmail.com
Sun May 20 01:20:09 PDT 2012
Hi,
The following program creates an array of 3 derived objects and
deletes them. However delete[] does not seem to call ~Derived( ) ,
i.e., destructor.
---------- derived_delete.cpp -----------
#include <iostream>
class Base
{
public:
Base() { }
virtual ~Base() {
std::cout << "In destructor " << __func__ << std::endl;
}
};
class Derived: public Base
{
public:
Derived() {}
~Derived() {
std::cout << "In destructor for " << __func__ << std::endl;
}
};
int main()
{
Base* ptr = new Derived[3];
delete [] ptr;
return 0;
}
---------- derived_delete.cpp -----------
The expected output is (e.g. with g++ or icpc):
In destructor for ~Derived
In destructor ~Base
In destructor for ~Derived
In destructor ~Base
In destructor for ~Derived
In destructor ~Base
but the actual output is:
In destructor ~Base
In destructor ~Base
In destructor ~Base
I'm running Clang v3.0 on x86_64 (Debian Squeeze).
Is there any existing bug report for this ?
PS: I'm not subscribed to the list, please keep me in cc.
--
-- Satish.BD
More information about the cfe-dev
mailing list