delete p
is equivalent to
p->~MyStruct();
operator delete(p);
unless MyStruct
has an alternative operator delete
, so your example should be well-defined with the expected semantics.
[expr.delete]/2
states:
the value of the operand of delete may be ... a pointer to a non-array object created by a previous new-expression.
Placement new is a type of new-expression. [expr.new]/1
:
new-expression:
::opt new new-placementopt new-type-id new-initializeropt
::opt new new-placementopt ( type-id ) new-initializeropt
delete
is defined to be a call to the destructor of the object and then a call to the deallocation function for the memory. [expr.delete]/6,7
:
... the delete-expression will invoke the destructor (if any) for the object ...
... the delete-expression will call a deallocation function ...
As long as the deallocation function matches the allocation function (which it should, as long as you haven't overloaded operator delete
for your class), then this should all be well defined.
new
, notdelete
. – Chansoo