Given two classes have only primitive data type and no custom destructor/deallocator. Does C++ spec guarantee it will deallocate with correct size?
struct A { in
This is undefined behaviour - maybe everything's fine, maybe whetever goes wrong. Either don't do it or supply the base class with a virtual destructor.
In most implementations this will not leak - there're no heap-allocated member functions in the class, so the only thing needed when delete
is done is to deallocate memory. Deallocating memory uses only the address of the object, nothing more, the heap does all the rest.