What does C++03 12.4/12 say about calling a base class destructor explicitly through the pointer?

Viewed 139

According to C++03 12.4/12 when a destructor is invoked explicitly

if the object is not of the destructor’s class type and not of a class derived from the destructor’s class type, the program has undefined behavior

So I have this code:

class Base {};
class Derived : public Base {};

char memory[100];
new(memory) Derived();
Base* ptr = (Base*)memory;
ptr->~Base();

Here the object is of type Derived and "the destructor's class type" is Base and so it looks like according to the Standard wording there're no grounds for UB.

So does the code above yield UB according to the Standard?

3 Answers
Related