delete expression

Destroys object(s) previously allocated by the new-expression and releases obtained memory area.

# Notes

A pointer to void cannot be deleted because it is not a pointer to an object type.

Because a pair of brackets following the keyword delete is always interpreted as the array form of a delete-expression, a lambda-expression with an empty capture list immediately after delete must be enclosed in parentheses.

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 288C++98for the first form, the static type of theoperand was compared with its dynamic typecompare the static type of the objectto be deleted with its dynamic type
CWG 353C++98whether the deallocation function will be invoked ifthe destructor throws an exception was unspecifiedalways invoked
CWG 599C++98the first form could take a null pointer ofany type, including function pointersexcept pointers to object types,all other pointer types are rejected
CWG 1642C++98expression could be a pointer lvaluenot allowed
CWG 2474C++98deleting a pointer to an object of a similar butdifferent type resulted in undefined behaviormade well-defined
CWG 2624C++98pointers obtained from non-allocatingoperator new[] could be passed to delete[]prohibited
CWG 2758C++98it was unclear how access control was done forthe deallocation function and the destructormade clear

# See also