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
It will deallocate with correct size, because the size to be deallocated is a property of the heap memory region you obtained (there is no size passed to free()
-like functions!).
However, no d'tor is called. If 'B' defines a destructor or contains any members with a non-trivial destructor they will not be called, causing a potential memory leak. This is not the case in your code sample, however.