From Jason Turner

[new.delete]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpnxmcgv06/{from.md → to.md} +205 -164
tmp/tmpnxmcgv06/{from.md → to.md} RENAMED
@@ -1,35 +1,43 @@
1
  ### Storage allocation and deallocation <a id="new.delete">[[new.delete]]</a>
2
 
3
- Except where otherwise specified, the provisions of (
4
- [[basic.stc.dynamic]]) apply to the library versions of `operator new`
5
  and `operator
6
- delete`.
 
7
 
8
  #### Single-object forms <a id="new.delete.single">[[new.delete.single]]</a>
9
 
10
  ``` cpp
11
  void* operator new(std::size_t size);
 
12
  ```
13
 
14
- *Effects:* The *allocation function* ([[basic.stc.dynamic.allocation]])
15
  called by a *new-expression* ([[expr.new]]) to allocate `size` bytes of
16
- storage suitably aligned to represent any object of that size.
 
 
 
 
17
 
18
- *Replaceable:* a C++program may define a function with this function
19
- signature that displaces the default version defined by the C++standard
20
- library.
21
 
22
  *Required behavior:* Return a non-null pointer to suitably aligned
23
  storage ([[basic.stc.dynamic]]), or else throw a `bad_alloc` exception.
24
- This requirement is binding on a replacement version of this function.
 
25
 
26
  *Default behavior:*
27
 
28
  - Executes a loop: Within the loop, the function first attempts to
29
  allocate the requested storage. Whether the attempt involves a call to
30
- the Standard C library function `malloc` is unspecified.
 
31
  - Returns a pointer to the allocated storage if the attempt is
32
  successful. Otherwise, if the current
33
  `new_handler` ([[get.new.handler]]) is a null pointer value, throws
34
  `bad_alloc`.
35
  - Otherwise, the function calls the current `new_handler`
@@ -38,277 +46,308 @@ This requirement is binding on a replacement version of this function.
38
  - The loop terminates when an attempt to allocate the requested storage
39
  is successful or when a called `new_handler` function does not return.
40
 
41
  ``` cpp
42
  void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
 
43
  ```
44
 
45
- *Effects:* Same as above, except that it is called by a placement
46
  version of a *new-expression* when a C++program prefers a null pointer
47
  result as an error indication, instead of a `bad_alloc` exception.
48
 
49
- *Replaceable:* a C++program may define a function with this function
50
- signature that displaces the default version defined by the C++standard
51
- library.
52
 
53
  *Required behavior:* Return a non-null pointer to suitably aligned
54
- storage ([[basic.stc.dynamic]]), or else return a null pointer. This
55
- nothrow version of `operator new` returns a pointer obtained as if
56
- acquired from the (possibly replaced) ordinary version. This requirement
57
- is binding on a replacement version of this function.
 
58
 
59
- *Default behavior:* Calls `operator new(size)`. If the call returns
 
60
  normally, returns the result of that call. Otherwise, returns a null
61
  pointer.
62
 
 
 
63
  ``` cpp
64
  T* p1 = new T; // throws bad_alloc if it fails
65
  T* p2 = new(nothrow) T; // returns nullptr if it fails
66
  ```
67
 
 
 
68
  ``` cpp
69
  void operator delete(void* ptr) noexcept;
70
  void operator delete(void* ptr, std::size_t size) noexcept;
 
 
71
  ```
72
 
73
- *Effects:* The *deallocation
74
- function* ([[basic.stc.dynamic.deallocation]]) called by a
75
  *delete-expression* to render the value of `ptr` invalid.
76
 
77
- *Replaceable:* a C++program may define a function with signature
78
- `void operator delete(void* ptr) noexcept` that displaces the default
79
- version defined by the C++standard library. If this function (without
80
- `size` parameter) is defined, the program should also define
81
- `void operator delete(void* ptr, std::size_t size) noexcept`. If this
82
- function with `size` parameter is defined, the program shall also define
83
- the version without the `size` parameter. The default behavior below may
84
- change in the future, which will require replacing both deallocation
85
- functions when replacing the allocation function.
86
 
87
- *Requires:* *ptr* shall be a null pointer or its value shall be a value
88
- returned by an earlier call to the (possibly replaced)
89
- `operator new(std::size_t)` or
90
- `operator new(std::size_t,const std::nothrow_t&)` which has not been
91
- invalidated by an intervening call to `operator delete(void*)`.
 
 
 
 
 
 
 
 
 
92
 
93
  *Requires:* If an implementation has strict pointer
94
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
95
  safely-derived pointer.
96
 
97
- *Requires:* If present, the `std::size_t size` argument shall equal the
98
- size argument passed to the allocation function that returned `ptr`.
 
 
 
 
99
 
100
- *Required behavior:* Calls to
101
- `operator delete(void* ptr, std::size_t size)` may be changed to calls
102
- to `operator delete(void* ptr)` without affecting memory allocation. A
103
- conforming implementation is for
 
 
104
  `operator delete(void* ptr, std::size_t size)` to simply call
105
- `operator delete(ptr)`.
106
 
107
- *Default behavior:* the function
108
- `operator delete(void* ptr, std::size_t size)` calls
109
- `operator delete(ptr)`. See the note in the above *Replaceable*
110
- paragraph.
 
 
111
 
112
  *Default behavior:* If `ptr` is null, does nothing. Otherwise, reclaims
113
  the storage allocated by the earlier call to `operator new`.
114
 
115
  *Remarks:* It is unspecified under what conditions part or all of such
116
  reclaimed storage will be allocated by subsequent calls to
117
- `operator new` or any of `calloc`, `malloc`, or `realloc`, declared in
118
- `<cstdlib>`.
119
 
120
  ``` cpp
121
  void operator delete(void* ptr, const std::nothrow_t&) noexcept;
122
- void operator delete(void* ptr, std::size_t size, const std::nothrow_t&) noexcept;
123
  ```
124
 
125
- *Effects:* The *deallocation
126
- function* ([[basic.stc.dynamic.deallocation]]) called by the
127
  implementation to render the value of `ptr` invalid when the constructor
128
  invoked from a nothrow placement version of the *new-expression* throws
129
  an exception.
130
 
131
- *Replaceable:* a C++program may define a function with signature
132
- `void operator delete(void* ptr, const std::nothrow_t&) noexcept` that
133
- displaces the default version defined by the C++standard library. If
134
- this function (without `size` parameter) is defined, the program should
135
- also define
136
- `void operator delete(void* ptr, std::size_t size, const std::nothrow_t&) noexcept`.
137
- If this function with `size` parameter is defined, the program shall
138
- also define the version without the `size` parameter. The default
139
- behavior below may change in the future, which will require replacing
140
- both deallocation functions when replacing the allocation function.
141
 
142
  *Requires:* If an implementation has strict pointer
143
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
144
  safely-derived pointer.
145
 
146
- *Requires:* If present, the `std::size_t size` argument must equal the
147
- size argument passed to the allocation function that returned `ptr`.
 
 
 
148
 
149
- *Required behavior:* Calls to
150
- `operator delete(void* ptr, std::size_t size, const std::nothrow_t&)`
151
- may be changed to calls to
152
- `operator delete(void* ptr, const std::nothrow_t&)` without affecting
153
- memory allocation. A conforming implementation is for
154
- `operator delete(void* ptr, std::size_t size, const std::nothrow_t&)` to
155
- simply call `operator delete(void* ptr, const std::nothrow_t&)`.
156
-
157
- *Default behavior:*
158
- `operator delete(void* ptr, std::size_t size, const std::nothrow_t&)`
159
- calls `operator delete(ptr, std::nothrow)`, and
160
- `operator delete(void* ptr, const std::nothrow_t&)` calls
161
- `operator delete(ptr)`.
162
 
163
  #### Array forms <a id="new.delete.array">[[new.delete.array]]</a>
164
 
165
  ``` cpp
166
  void* operator new[](std::size_t size);
 
167
  ```
168
 
169
- *Effects:* The *allocation function* ([[basic.stc.dynamic.allocation]])
170
  called by the array form of a *new-expression* ([[expr.new]]) to
171
- allocate `size` bytes of storage suitably aligned to represent any array
172
- object of that size or smaller.[^33]
 
 
 
173
 
174
- *Replaceable:* a C++program can define a function with this function
175
- signature that displaces the default version defined by the C++standard
176
- library.
177
 
178
- *Required behavior:* Same as for `operator new(std::size_t)`. This
179
- requirement is binding on a replacement version of this function.
 
180
 
181
- *Default behavior:* Returns `operator new(size)`.
 
182
 
183
  ``` cpp
184
  void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;
 
185
  ```
186
 
187
- *Effects:* Same as above, except that it is called by a placement
188
  version of a *new-expression* when a C++program prefers a null pointer
189
  result as an error indication, instead of a `bad_alloc` exception.
190
 
191
- *Replaceable:* a C++program can define a function with this function
192
- signature that displaces the default version defined by the C++standard
193
- library.
194
 
195
  *Required behavior:* Return a non-null pointer to suitably aligned
196
- storage ([[basic.stc.dynamic]]), or return a null pointer. This
197
- requirement is binding on a replacement version of this function.
 
 
 
198
 
199
- *Default behavior:* Calls `operator new[](size)`. If the call returns
 
200
  normally, returns the result of that call. Otherwise, returns a null
201
  pointer.
202
 
203
  ``` cpp
204
  void operator delete[](void* ptr) noexcept;
205
  void operator delete[](void* ptr, std::size_t size) noexcept;
 
 
206
  ```
207
 
208
- *Effects:* The *deallocation
209
- function* ([[basic.stc.dynamic.deallocation]]) called by the array form
210
  of a *delete-expression* to render the value of `ptr` invalid.
211
 
212
- *Replaceable:* a C++program can define a function with signature
213
- `void operator delete[](void* ptr) noexcept` that displaces the default
214
- version defined by the C++standard library. If this function (without
215
- `size` parameter) is defined, the program should also define
216
- `void operator delete[](void* ptr, std::size_t size) noexcept`. If this
217
- function with `size` parameter is defined, the program shall also define
218
- the version without the `size` parameter. The default behavior below may
219
- change in the future, which will require replacing both deallocation
220
- functions when replacing the allocation function.
221
 
222
- *Requires:* *ptr* shall be a null pointer or its value shall be the
223
- value returned by an earlier call to `operator new[](std::size_t)` or
224
- `operator new[](std::size_t,const std::nothrow_t&)` which has not been
225
- invalidated by an intervening call to `operator delete[](void*)`.
226
 
227
- *Requires:* If present, the `std::size_t size` argument must equal the
228
- size argument passed to the allocation function that returned `ptr`.
 
229
 
230
- *Required behavior:* Calls to
231
- `operator delete[](void* ptr, std::size_t size)` may be changed to calls
232
- to `operator delete[](void* ptr)` without affecting memory allocation. A
233
- conforming implementation is for
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  `operator delete[](void* ptr, std::size_t size)` to simply call
235
- `operator delete[](void* ptr)`.
236
 
237
- *Requires:* If an implementation has strict pointer
238
- safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
239
- safely-derived pointer.
240
-
241
- *Default behavior:* `operator delete[](void* ptr, std::size_t size)`
242
- calls `operator delete[](ptr)`, and `operator delete[](void* ptr)` calls
243
- `operator delete(ptr)`.
244
 
245
  ``` cpp
246
  void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
247
- void operator delete[](void* ptr, std::size_t size, const std::nothrow_t&) noexcept;
248
  ```
249
 
250
- *Effects:* The *deallocation
251
- function* ([[basic.stc.dynamic.deallocation]]) called by the
252
  implementation to render the value of `ptr` invalid when the constructor
253
  invoked from a nothrow placement version of the array *new-expression*
254
  throws an exception.
255
 
256
- *Replaceable:* a C++program may define a function with signature
257
- `void operator delete[](void* ptr, const std::nothrow_t&) noexcept` that
258
- displaces the default version defined by the C++standard library. If
259
- this function (without `size` parameter) is defined, the program should
260
- also define
261
- `void operator delete[](void* ptr, std::size_t size, const std::nothrow_t&) noexcept`.
262
- If this function with `size` parameter is defined, the program shall
263
- also define the version without the `size` parameter. The default
264
- behavior below may change in the future, which will require replacing
265
- both deallocation functions when replacing the allocation function.
266
 
267
  *Requires:* If an implementation has strict pointer
268
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
269
  safely-derived pointer.
270
 
271
- *Requires:* If present, the `std::size_t size` argument must equal the
272
- size argument passed to the allocation function that returned `ptr`.
 
 
 
273
 
274
- *Required behavior:* Calls to
275
- `operator delete[](void* ptr, std::size_t size, const std::nothrow_t&)`
276
- may be changed to calls to
277
- `operator delete[](void* ptr, const std::nothrow_t&)` without affecting
278
- memory allocation. A conforming implementation is for
279
- `operator delete[](void* ptr, std::size_t size, const std::nothrow_t&)`
280
- to simply call `operator delete[](void* ptr, const std::nothrow_t&)`.
281
 
282
- *Default behavior:*
283
- `operator delete[](void* ptr, std::size_t size, const std::nothrow_t&)`
284
- calls `operator delete[](ptr, std::nothrow)`, and
285
- `operator delete[](void* ptr, const std::nothrow_t&)` calls
286
- `operator delete[](ptr)`.
287
 
288
- #### Placement forms <a id="new.delete.placement">[[new.delete.placement]]</a>
289
-
290
- These functions are reserved, a C++program may not define functions that
291
- displace the versions in the Standard C++library ([[constraints]]). The
292
- provisions of ([[basic.stc.dynamic]]) do not apply to these reserved
293
  placement forms of `operator new` and `operator delete`.
294
 
295
  ``` cpp
296
  void* operator new(std::size_t size, void* ptr) noexcept;
297
  ```
298
 
299
  *Returns:* `ptr`.
300
 
301
  *Remarks:* Intentionally performs no other action.
302
 
 
 
303
  This can be useful for constructing an object at a known address:
304
 
305
  ``` cpp
306
  void* place = operator new(sizeof(Something));
307
  Something* p = new (place) Something();
308
  ```
309
 
 
 
310
  ``` cpp
311
  void* operator new[](std::size_t size, void* ptr) noexcept;
312
  ```
313
 
314
  *Returns:* `ptr`.
@@ -324,11 +363,11 @@ void operator delete(void* ptr, void*) noexcept;
324
  *Requires:* If an implementation has strict pointer
325
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
326
  safely-derived pointer.
327
 
328
  *Remarks:* Default function called when any part of the initialization
329
- in a placement new expression that invokes the library’s non-array
330
  placement operator new terminates by throwing an
331
  exception ([[expr.new]]).
332
 
333
  ``` cpp
334
  void operator delete[](void* ptr, void*) noexcept;
@@ -339,21 +378,23 @@ void operator delete[](void* ptr, void*) noexcept;
339
  *Requires:* If an implementation has strict pointer
340
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
341
  safely-derived pointer.
342
 
343
  *Remarks:* Default function called when any part of the initialization
344
- in a placement new expression that invokes the library’s array placement
345
- operator new terminates by throwing an exception ([[expr.new]]).
 
346
 
347
  #### Data races <a id="new.delete.dataraces">[[new.delete.dataraces]]</a>
348
 
349
  For purposes of determining the existence of data races, the library
350
  versions of `operator new`, user replacement versions of global
351
- `operator new`, the C standard library functions `calloc` and `malloc`,
352
- the library versions of `operator delete`, user replacement versions of
353
- `operator delete`, the C standard library function `free`, and the C
354
- standard library function `realloc` shall not introduce a data race (
355
- [[res.on.data.races]]). Calls to these functions that allocate or
356
- deallocate a particular unit of storage shall occur in a single total
357
- order, and each such deallocation call shall happen before (
358
- [[intro.multithread]]) the next allocation (if any) in this order.
 
359
 
 
1
  ### Storage allocation and deallocation <a id="new.delete">[[new.delete]]</a>
2
 
3
+ Except where otherwise specified, the provisions of 
4
+ [[basic.stc.dynamic]] apply to the library versions of `operator new`
5
  and `operator
6
+ delete`. If the value of an alignment argument passed to any of these
7
+ functions is not a valid alignment value, the behavior is undefined.
8
 
9
  #### Single-object forms <a id="new.delete.single">[[new.delete.single]]</a>
10
 
11
  ``` cpp
12
  void* operator new(std::size_t size);
13
+ void* operator new(std::size_t size, std::align_val_t alignment);
14
  ```
15
 
16
+ *Effects:* The allocation functions ([[basic.stc.dynamic.allocation]])
17
  called by a *new-expression* ([[expr.new]]) to allocate `size` bytes of
18
+ storage. The second form is called for a type with new-extended
19
+ alignment, and allocates storage with the specified alignment. The first
20
+ form is called otherwise, and allocates storage suitably aligned to
21
+ represent any object of that size provided the object’s type does not
22
+ have new-extended alignment.
23
 
24
+ *Replaceable:* A C++program may define functions with either of these
25
+ function signatures, and thereby displace the default versions defined
26
+ by the C++standard library.
27
 
28
  *Required behavior:* Return a non-null pointer to suitably aligned
29
  storage ([[basic.stc.dynamic]]), or else throw a `bad_alloc` exception.
30
+ This requirement is binding on any replacement versions of these
31
+ functions.
32
 
33
  *Default behavior:*
34
 
35
  - Executes a loop: Within the loop, the function first attempts to
36
  allocate the requested storage. Whether the attempt involves a call to
37
+ the C standard library functions `malloc` or `aligned_alloc` is
38
+ unspecified.
39
  - Returns a pointer to the allocated storage if the attempt is
40
  successful. Otherwise, if the current
41
  `new_handler` ([[get.new.handler]]) is a null pointer value, throws
42
  `bad_alloc`.
43
  - Otherwise, the function calls the current `new_handler`
 
46
  - The loop terminates when an attempt to allocate the requested storage
47
  is successful or when a called `new_handler` function does not return.
48
 
49
  ``` cpp
50
  void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
51
+ void* operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
52
  ```
53
 
54
+ *Effects:* Same as above, except that these are called by a placement
55
  version of a *new-expression* when a C++program prefers a null pointer
56
  result as an error indication, instead of a `bad_alloc` exception.
57
 
58
+ *Replaceable:* A C++program may define functions with either of these
59
+ function signatures, and thereby displace the default versions defined
60
+ by the C++standard library.
61
 
62
  *Required behavior:* Return a non-null pointer to suitably aligned
63
+ storage ([[basic.stc.dynamic]]), or else return a null pointer. Each of
64
+ these nothrow versions of `operator new` returns a pointer obtained as
65
+ if acquired from the (possibly replaced) corresponding non-placement
66
+ function. This requirement is binding on any replacement versions of
67
+ these functions.
68
 
69
+ *Default behavior:* Calls `operator new(size)`, or
70
+ `operator new(size, alignment)`, respectively. If the call returns
71
  normally, returns the result of that call. Otherwise, returns a null
72
  pointer.
73
 
74
+ [*Example 1*:
75
+
76
  ``` cpp
77
  T* p1 = new T; // throws bad_alloc if it fails
78
  T* p2 = new(nothrow) T; // returns nullptr if it fails
79
  ```
80
 
81
+ — *end example*]
82
+
83
  ``` cpp
84
  void operator delete(void* ptr) noexcept;
85
  void operator delete(void* ptr, std::size_t size) noexcept;
86
+ void operator delete(void* ptr, std::align_val_t alignment) noexcept;
87
+ void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
88
  ```
89
 
90
+ *Effects:* The deallocation
91
+ functions ([[basic.stc.dynamic.deallocation]]) called by a
92
  *delete-expression* to render the value of `ptr` invalid.
93
 
94
+ *Replaceable:* A C++program may define functions with any of these
95
+ function signatures, and thereby displace the default versions defined
96
+ by the C++standard library.
 
 
 
 
 
 
97
 
98
+ If a function without a `size` parameter is defined, the program should
99
+ also define the corresponding function with a `size` parameter. If a
100
+ function with a `size` parameter is defined, the program shall also
101
+ define the corresponding version without the `size` parameter.
102
+
103
+ [*Note 1*: The default behavior below may change in the future, which
104
+ will require replacing both deallocation functions when replacing the
105
+ allocation function. — *end note*]
106
+
107
+ *Requires:* `ptr` shall be a null pointer or its value shall represent
108
+ the address of a block of memory allocated by an earlier call to a
109
+ (possibly replaced) `operator new(std::size_t)` or
110
+ `operator new(std::size_t, std::align_val_t)` which has not been
111
+ invalidated by an intervening call to `operator delete`.
112
 
113
  *Requires:* If an implementation has strict pointer
114
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
115
  safely-derived pointer.
116
 
117
+ *Requires:* If the `alignment` parameter is not present, `ptr` shall
118
+ have been returned by an allocation function without an `alignment`
119
+ parameter. If present, the `alignment` argument shall equal the
120
+ `alignment` argument passed to the allocation function that returned
121
+ `ptr`. If present, the `size` argument shall equal the `size` argument
122
+ passed to the allocation function that returned `ptr`.
123
 
124
+ *Required behavior:* A call to an `operator delete` with a `size`
125
+ parameter may be changed to a call to the corresponding
126
+ `operator delete` without a `size` parameter, without affecting memory
127
+ allocation.
128
+
129
+ [*Note 2*: A conforming implementation is for
130
  `operator delete(void* ptr, std::size_t size)` to simply call
131
+ `operator delete(ptr)`. — *end note*]
132
 
133
+ *Default behavior:* The functions that have a `size` parameter forward
134
+ their other parameters to the corresponding function without a `size`
135
+ parameter.
136
+
137
+ [*Note 3*: See the note in the above *Replaceable:*
138
+ paragraph. — *end note*]
139
 
140
  *Default behavior:* If `ptr` is null, does nothing. Otherwise, reclaims
141
  the storage allocated by the earlier call to `operator new`.
142
 
143
  *Remarks:* It is unspecified under what conditions part or all of such
144
  reclaimed storage will be allocated by subsequent calls to
145
+ `operator new` or any of `aligned_alloc`, `calloc`, `malloc`, or
146
+ `realloc`, declared in `<cstdlib>`.
147
 
148
  ``` cpp
149
  void operator delete(void* ptr, const std::nothrow_t&) noexcept;
150
+ void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
151
  ```
152
 
153
+ *Effects:* The deallocation
154
+ functions ([[basic.stc.dynamic.deallocation]]) called by the
155
  implementation to render the value of `ptr` invalid when the constructor
156
  invoked from a nothrow placement version of the *new-expression* throws
157
  an exception.
158
 
159
+ *Replaceable:* A C++program may define functions with either of these
160
+ function signatures, and thereby displace the default versions defined
161
+ by the C++standard library.
162
+
163
+ *Requires:* `ptr` shall be a null pointer or its value shall represent
164
+ the address of a block of memory allocated by an earlier call to a
165
+ (possibly replaced) `operator new(std::size_t)` or
166
+ `operator new(std::size_t, std::align_val_t)` which has not been
167
+ invalidated by an intervening call to `operator delete`.
 
168
 
169
  *Requires:* If an implementation has strict pointer
170
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
171
  safely-derived pointer.
172
 
173
+ *Requires:* If the `alignment` parameter is not present, `ptr` shall
174
+ have been returned by an allocation function without an `alignment`
175
+ parameter. If present, the `alignment` argument shall equal the
176
+ `alignment` argument passed to the allocation function that returned
177
+ `ptr`.
178
 
179
+ *Default behavior:* Calls `operator delete(ptr)`, or
180
+ `operator delete(ptr, alignment)`, respectively.
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  #### Array forms <a id="new.delete.array">[[new.delete.array]]</a>
183
 
184
  ``` cpp
185
  void* operator new[](std::size_t size);
186
+ void* operator new[](std::size_t size, std::align_val_t alignment);
187
  ```
188
 
189
+ *Effects:* The allocation functions ([[basic.stc.dynamic.allocation]])
190
  called by the array form of a *new-expression* ([[expr.new]]) to
191
+ allocate `size` bytes of storage. The second form is called for a type
192
+ with new-extended alignment, and allocates storage with the specified
193
+ alignment. The first form is called otherwise, and allocates storage
194
+ suitably aligned to represent any array object of that size or smaller,
195
+ provided the object’s type does not have new-extended alignment. [^33]
196
 
197
+ *Replaceable:* A C++program may define functions with either of these
198
+ function signatures, and thereby displace the default versions defined
199
+ by the C++standard library.
200
 
201
+ *Required behavior:* Same as for the corresponding single-object forms.
202
+ This requirement is binding on any replacement versions of these
203
+ functions.
204
 
205
+ *Default behavior:* Returns `operator new(size)`, or
206
+ `operator new(size, alignment)`, respectively.
207
 
208
  ``` cpp
209
  void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;
210
+ void* operator new[](std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
211
  ```
212
 
213
+ *Effects:* Same as above, except that these are called by a placement
214
  version of a *new-expression* when a C++program prefers a null pointer
215
  result as an error indication, instead of a `bad_alloc` exception.
216
 
217
+ *Replaceable:* A C++program may define functions with either of these
218
+ function signatures, and thereby displace the default versions defined
219
+ by the C++standard library.
220
 
221
  *Required behavior:* Return a non-null pointer to suitably aligned
222
+ storage ([[basic.stc.dynamic]]), or else return a null pointer. Each of
223
+ these nothrow versions of `operator new[]` returns a pointer obtained as
224
+ if acquired from the (possibly replaced) corresponding non-placement
225
+ function. This requirement is binding on any replacement versions of
226
+ these functions.
227
 
228
+ *Default behavior:* Calls `operator new[](size)`, or
229
+ `operator new[](size, alignment)`, respectively. If the call returns
230
  normally, returns the result of that call. Otherwise, returns a null
231
  pointer.
232
 
233
  ``` cpp
234
  void operator delete[](void* ptr) noexcept;
235
  void operator delete[](void* ptr, std::size_t size) noexcept;
236
+ void operator delete[](void* ptr, std::align_val_t alignment) noexcept;
237
+ void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
238
  ```
239
 
240
+ *Effects:* The deallocation
241
+ functions ([[basic.stc.dynamic.deallocation]]) called by the array form
242
  of a *delete-expression* to render the value of `ptr` invalid.
243
 
244
+ *Replaceable:* A C++program may define functions with any of these
245
+ function signatures, and thereby displace the default versions defined
246
+ by the C++standard library.
 
 
 
 
 
 
247
 
248
+ If a function without a `size` parameter is defined, the program should
249
+ also define the corresponding function with a `size` parameter. If a
250
+ function with a `size` parameter is defined, the program shall also
251
+ define the corresponding version without the `size` parameter.
252
 
253
+ [*Note 1*: The default behavior below may change in the future, which
254
+ will require replacing both deallocation functions when replacing the
255
+ allocation function. — *end note*]
256
 
257
+ *Requires:* `ptr` shall be a null pointer or its value shall represent
258
+ the address of a block of memory allocated by an earlier call to a
259
+ (possibly replaced) `operator new[](std::size_t)` or
260
+ `operator new[](std::size_t, std::align_val_t)` which has not been
261
+ invalidated by an intervening call to `operator delete[]`.
262
+
263
+ *Requires:* If an implementation has strict pointer
264
+ safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
265
+ safely-derived pointer.
266
+
267
+ *Requires:* If the `alignment` parameter is not present, `ptr` shall
268
+ have been returned by an allocation function without an `alignment`
269
+ parameter. If present, the `alignment` argument shall equal the
270
+ `alignment` argument passed to the allocation function that returned
271
+ `ptr`. If present, the `size` argument shall equal the `size` argument
272
+ passed to the allocation function that returned `ptr`.
273
+
274
+ *Required behavior:* A call to an `operator delete[]` with a `size`
275
+ parameter may be changed to a call to the corresponding
276
+ `operator delete[]` without a `size` parameter, without affecting memory
277
+ allocation.
278
+
279
+ [*Note 2*: A conforming implementation is for
280
  `operator delete[](void* ptr, std::size_t size)` to simply call
281
+ `operator delete[](ptr)`. — *end note*]
282
 
283
+ *Default behavior:* The functions that have a `size` parameter forward
284
+ their other parameters to the corresponding function without a `size`
285
+ parameter. The functions that do not have a `size` parameter forward
286
+ their parameters to the corresponding `operator delete` (single-object)
287
+ function.
 
 
288
 
289
  ``` cpp
290
  void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
291
+ void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
292
  ```
293
 
294
+ *Effects:* The deallocation
295
+ functions ([[basic.stc.dynamic.deallocation]]) called by the
296
  implementation to render the value of `ptr` invalid when the constructor
297
  invoked from a nothrow placement version of the array *new-expression*
298
  throws an exception.
299
 
300
+ *Replaceable:* A C++program may define functions with either of these
301
+ function signatures, and thereby displace the default versions defined
302
+ by the C++standard library.
303
+
304
+ *Requires:* `ptr` shall be a null pointer or its value shall represent
305
+ the address of a block of memory allocated by an earlier call to a
306
+ (possibly replaced) `operator new[](std::size_t)` or
307
+ `operator new[](std::size_t, std::align_val_t)` which has not been
308
+ invalidated by an intervening call to `operator delete[]`.
 
309
 
310
  *Requires:* If an implementation has strict pointer
311
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
312
  safely-derived pointer.
313
 
314
+ *Requires:* If the `alignment` parameter is not present, `ptr` shall
315
+ have been returned by an allocation function without an `alignment`
316
+ parameter. If present, the `alignment` argument shall equal the
317
+ `alignment` argument passed to the allocation function that returned
318
+ `ptr`.
319
 
320
+ *Default behavior:* Calls `operator delete[](ptr)`, or
321
+ `operator delete[](ptr, alignment)`, respectively.
 
 
 
 
 
322
 
323
+ #### Non-allocating forms <a id="new.delete.placement">[[new.delete.placement]]</a>
 
 
 
 
324
 
325
+ These functions are reserved; a C++program may not define functions that
326
+ displace the versions in the C++standard library ([[constraints]]). The
327
+ provisions of  [[basic.stc.dynamic]] do not apply to these reserved
 
 
328
  placement forms of `operator new` and `operator delete`.
329
 
330
  ``` cpp
331
  void* operator new(std::size_t size, void* ptr) noexcept;
332
  ```
333
 
334
  *Returns:* `ptr`.
335
 
336
  *Remarks:* Intentionally performs no other action.
337
 
338
+ [*Example 1*:
339
+
340
  This can be useful for constructing an object at a known address:
341
 
342
  ``` cpp
343
  void* place = operator new(sizeof(Something));
344
  Something* p = new (place) Something();
345
  ```
346
 
347
+ — *end example*]
348
+
349
  ``` cpp
350
  void* operator new[](std::size_t size, void* ptr) noexcept;
351
  ```
352
 
353
  *Returns:* `ptr`.
 
363
  *Requires:* If an implementation has strict pointer
364
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
365
  safely-derived pointer.
366
 
367
  *Remarks:* Default function called when any part of the initialization
368
+ in a placement *new-expression* that invokes the library’s non-array
369
  placement operator new terminates by throwing an
370
  exception ([[expr.new]]).
371
 
372
  ``` cpp
373
  void operator delete[](void* ptr, void*) noexcept;
 
378
  *Requires:* If an implementation has strict pointer
379
  safety ([[basic.stc.dynamic.safety]]) then `ptr` shall be a
380
  safely-derived pointer.
381
 
382
  *Remarks:* Default function called when any part of the initialization
383
+ in a placement *new-expression* that invokes the library’s array
384
+ placement operator new terminates by throwing an
385
+ exception ([[expr.new]]).
386
 
387
  #### Data races <a id="new.delete.dataraces">[[new.delete.dataraces]]</a>
388
 
389
  For purposes of determining the existence of data races, the library
390
  versions of `operator new`, user replacement versions of global
391
+ `operator new`, the C standard library functions `aligned_alloc`,
392
+ `calloc`, and `malloc`, the library versions of `operator delete`, user
393
+ replacement versions of `operator delete`, the C standard library
394
+ function `free`, and the C standard library function `realloc` shall not
395
+ introduce a data race ([[res.on.data.races]]). Calls to these functions
396
+ that allocate or deallocate a particular unit of storage shall occur in
397
+ a single total order, and each such deallocation call shall happen
398
+ before ([[intro.multithread]]) the next allocation (if any) in this
399
+ order.
400