Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The C++ Standard, [expr.delete], paragraph 2 [ISO/IEC 14882-2014], states in part:

In the first alternative (delete object), the value of the operand of delete may be a null pointer value, a pointer to a non-array object created by a previous new-expression, or a pointer to a subobject (1.8) representing a base class of such an object (Clause 10). If not, the behavior is undefined. In the second alternative (delete array), the value of the operand of delete may be a null pointer value or a pointer value that resulted from a previous array new-expression. If not, the behavior is undefined.

...

In this noncompliant code example, the class C is given ownership of a P *, which is subsequently deleted by the class destructor. The C++ Standard, [class.copy], paragraph 7, states [ISO/IEC 14882-2014]: 

If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor.

...

[Dowd 2007]"Attacking delete and delete [] in C++"
[Henricson 1997]Rule 8.1, delete should only be used with new
Rule 8.2, delete [] should only be used with new []
[ISO/IEC 14882-2014]

Subclause 5.3.5, "Delete"
Subclause 12.8, "Copying and Moving Class Objects"
Subclause 18.6.1, "Storage Allocation and Deallocation"
Subclause 20.7.11, "Temporary Buffers" 

[Meyers 2005]Item 16, "Use the Same Form in Corresponding Uses of new and delete"
[Seacord 2013]Chapter 4, "Dynamic Memory Management"
[Viega 05]"Doubly Freeing Memory"

...