From Jason Turner

[expr.delete]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpns8d6xa2/{from.md → to.md} +56 -25
tmp/tmpns8d6xa2/{from.md → to.md} RENAMED
@@ -26,16 +26,20 @@ pointer to a non-array object created by a previous *new-expression*, or
26
  a pointer to a subobject ([[intro.object]]) representing a base class
27
  of such an object (Clause  [[class.derived]]). If not, the behavior is
28
  undefined. In the second alternative (*delete array*), the value of the
29
  operand of `delete` may be a null pointer value or a pointer value that
30
  resulted from a previous array *new-expression*.[^22] If not, the
31
- behavior is undefined. this means that the syntax of the
32
- *delete-expression* must match the type of the object allocated by
33
- `new`, not the syntax of the *new-expression*. a pointer to a `const`
34
- type can be the operand of a *delete-expression*; it is not necessary to
35
- cast away the constness ([[expr.const.cast]]) of the pointer expression
36
- before it is used as the operand of the *delete-expression*.
 
 
 
 
37
 
38
  In the first alternative (*delete object*), if the static type of the
39
  object to be deleted is different from its dynamic type, the static type
40
  shall be a base class of the dynamic type of the object to be deleted
41
  and the static type shall have a virtual destructor or the behavior is
@@ -72,42 +76,69 @@ pointer value, then:
72
  *new-expression* that had storage provided by the extended
73
  *new-expression* has been evaluated, the *delete-expression* shall
74
  call a deallocation function. The value returned from the allocation
75
  call of the extended *new-expression* shall be passed as the first
76
  argument to the deallocation function.
77
- - Otherwise, the *delete-expression* will not call a *deallocation
78
- function* ([[basic.stc.dynamic.deallocation]]).
79
 
80
- Otherwise, it is unspecified whether the deallocation function will be
81
- called. The deallocation function is called regardless of whether the
82
- destructor for the object or some element of the array throws an
83
- exception.
84
 
85
- An implementation provides default definitions of the global
86
- deallocation functions `operator delete()` for non-arrays (
87
- [[new.delete.single]]) and `operator delete[]()` for arrays (
 
 
 
 
88
  [[new.delete.array]]). A C++ program can provide alternative definitions
89
  of these functions ([[replacement.functions]]), and/or class-specific
90
- versions ([[class.free]]).
91
 
92
  When the keyword `delete` in a *delete-expression* is preceded by the
93
  unary `::` operator, the deallocation function’s name is looked up in
94
  global scope. Otherwise, the lookup considers class-specific
95
  deallocation functions ([[class.free]]). If no class-specific
96
  deallocation function is found, the deallocation function’s name is
97
  looked up in global scope.
98
 
99
- If the type is complete and if deallocation function lookup finds both a
100
- usual deallocation function with only a pointer parameter and a usual
101
- deallocation function with both a pointer parameter and a size
102
- parameter, then the selected deallocation function shall be the one with
103
- two parameters. Otherwise, the selected deallocation function shall be
104
- the function with one parameter.
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  When a *delete-expression* is executed, the selected deallocation
107
- function shall be called with the address of the block of storage to be
108
- reclaimed as its first argument and (if the two-parameter deallocation
109
- function is used) the size of the block as its second argument.[^23]
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  Access and ambiguity control are done for both the deallocation function
112
  and the destructor ([[class.dtor]],  [[class.free]]).
113
 
 
26
  a pointer to a subobject ([[intro.object]]) representing a base class
27
  of such an object (Clause  [[class.derived]]). If not, the behavior is
28
  undefined. In the second alternative (*delete array*), the value of the
29
  operand of `delete` may be a null pointer value or a pointer value that
30
  resulted from a previous array *new-expression*.[^22] If not, the
31
+ behavior is undefined.
32
+
33
+ [*Note 1*: This means that the syntax of the *delete-expression* must
34
+ match the type of the object allocated by `new`, not the syntax of the
35
+ *new-expression*. *end note*]
36
+
37
+ [*Note 2*: A pointer to a `const` type can be the operand of a
38
+ *delete-expression*; it is not necessary to cast away the constness (
39
+ [[expr.const.cast]]) of the pointer expression before it is used as the
40
+ operand of the *delete-expression*. — *end note*]
41
 
42
  In the first alternative (*delete object*), if the static type of the
43
  object to be deleted is different from its dynamic type, the static type
44
  shall be a base class of the dynamic type of the object to be deleted
45
  and the static type shall have a virtual destructor or the behavior is
 
76
  *new-expression* that had storage provided by the extended
77
  *new-expression* has been evaluated, the *delete-expression* shall
78
  call a deallocation function. The value returned from the allocation
79
  call of the extended *new-expression* shall be passed as the first
80
  argument to the deallocation function.
81
+ - Otherwise, the *delete-expression* will not call a deallocation
82
+ function.
83
 
84
+ [*Note 3*: The deallocation function is called regardless of whether
85
+ the destructor for the object or some element of the array throws an
86
+ exception. *end note*]
 
87
 
88
+ If the value of the operand of the *delete-expression* is a null pointer
89
+ value, it is unspecified whether a deallocation function will be called
90
+ as described above.
91
+
92
+ [*Note 4*: An implementation provides default definitions of the global
93
+ deallocation functions `operator delete` for non-arrays (
94
+ [[new.delete.single]]) and `operator delete[]` for arrays (
95
  [[new.delete.array]]). A C++ program can provide alternative definitions
96
  of these functions ([[replacement.functions]]), and/or class-specific
97
+ versions ([[class.free]]). — *end note*]
98
 
99
  When the keyword `delete` in a *delete-expression* is preceded by the
100
  unary `::` operator, the deallocation function’s name is looked up in
101
  global scope. Otherwise, the lookup considers class-specific
102
  deallocation functions ([[class.free]]). If no class-specific
103
  deallocation function is found, the deallocation function’s name is
104
  looked up in global scope.
105
 
106
+ If deallocation function lookup finds more than one usual deallocation
107
+ function, the function to be called is selected as follows:
108
+
109
+ - If the type has new-extended alignment, a function with a parameter of
110
+ type `std::align_val_t` is preferred; otherwise a function without
111
+ such a parameter is preferred. If exactly one preferred function is
112
+ found, that function is selected and the selection process terminates.
113
+ If more than one preferred function is found, all non-preferred
114
+ functions are eliminated from further consideration.
115
+ - If the deallocation functions have class scope, the one without a
116
+ parameter of type `std::size_t` is selected.
117
+ - If the type is complete and if, for the second alternative (delete
118
+ array) only, the operand is a pointer to a class type with a
119
+ non-trivial destructor or a (possibly multi-dimensional) array
120
+ thereof, the function with a parameter of type `std::size_t` is
121
+ selected.
122
+ - Otherwise, it is unspecified whether a deallocation function with a
123
+ parameter of type `std::size_t` is selected.
124
 
125
  When a *delete-expression* is executed, the selected deallocation
126
+ function shall be called with the address of the most-derived object in
127
+ the *delete object* case, or the address of the object suitably adjusted
128
+ for the array allocation overhead ([[expr.new]]) in the *delete array*
129
+ case, as its first argument. If a deallocation function with a parameter
130
+ of type `std::align_val_t` is used, the alignment of the type of the
131
+ object to be deleted is passed as the corresponding argument. If a
132
+ deallocation function with a parameter of type `std::size_t` is used,
133
+ the size of the most-derived type, or of the array plus allocation
134
+ overhead, respectively, is passed as the corresponding argument. [^23]
135
+
136
+ [*Note 5*: If this results in a call to a usual deallocation function,
137
+ and either the first argument was not the result of a prior call to a
138
+ usual allocation function or the second argument was not the
139
+ corresponding argument in said call, the behavior is undefined (
140
+ [[new.delete.single]], [[new.delete.array]]). — *end note*]
141
 
142
  Access and ambiguity control are done for both the deallocation function
143
  and the destructor ([[class.dtor]],  [[class.free]]).
144