If you use any form of placing new, except for versions of std::nothrow_t , you need to explicitly destroy the object and free its memory by any means that you consider necessary. However, an overloaded version of operator delete() must exist because it is used if building an object throws an exception! In this case, no pointer is returned since an exception is thrown. Therefore, memory disposal should be performed in this allocation process.
That is, you main() should look something like this:
int main() { foo* p = new (static_cast<foo*>(0)) foo; p->~foo(); operator delete(p, static_cast<foo*>(0)); }
Dietmar Kühl
source share