tmp/tmp8icuwf44/{from.md → to.md}
RENAMED
|
@@ -1,14 +1,17 @@
|
|
| 1 |
## Dynamic memory management <a id="support.dynamic">[[support.dynamic]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
The header `<new>` defines several functions that manage the allocation
|
| 4 |
of dynamic storage in a program. It also defines components for
|
| 5 |
reporting storage management errors.
|
| 6 |
|
| 7 |
### Header `<new>` synopsis <a id="new.syn">[[new.syn]]</a>
|
| 8 |
|
| 9 |
``` cpp
|
|
|
|
| 10 |
namespace std {
|
| 11 |
// [alloc.errors], storage allocation errors
|
| 12 |
class bad_alloc;
|
| 13 |
class bad_array_new_length;
|
| 14 |
|
|
@@ -73,10 +76,12 @@ void operator delete (void* ptr, void*) noexcept;
|
|
| 73 |
void operator delete[](void* ptr, void*) noexcept;
|
| 74 |
```
|
| 75 |
|
| 76 |
### Storage allocation and deallocation <a id="new.delete">[[new.delete]]</a>
|
| 77 |
|
|
|
|
|
|
|
| 78 |
Except where otherwise specified, the provisions of
|
| 79 |
[[basic.stc.dynamic]] apply to the library versions of `operator new`
|
| 80 |
and `operator
|
| 81 |
delete`. If the value of an alignment argument passed to any of these
|
| 82 |
functions is not a valid alignment value, the behavior is undefined.
|
|
@@ -157,10 +162,23 @@ void operator delete(void* ptr) noexcept;
|
|
| 157 |
void operator delete(void* ptr, std::size_t size) noexcept;
|
| 158 |
void operator delete(void* ptr, std::align_val_t alignment) noexcept;
|
| 159 |
void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 160 |
```
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 163 |
called by a *delete-expression*[[expr.delete]] to render the value of
|
| 164 |
`ptr` invalid.
|
| 165 |
|
| 166 |
*Replaceable:* A C++ program may define functions with any of these
|
|
@@ -170,31 +188,14 @@ by the C++ standard library.
|
|
| 170 |
If a function without a `size` parameter is defined, the program should
|
| 171 |
also define the corresponding function with a `size` parameter. If a
|
| 172 |
function with a `size` parameter is defined, the program shall also
|
| 173 |
define the corresponding version without the `size` parameter.
|
| 174 |
|
| 175 |
-
[*Note 1*: The default behavior below
|
| 176 |
will require replacing both deallocation functions when replacing the
|
| 177 |
allocation function. — *end note*]
|
| 178 |
|
| 179 |
-
*Preconditions:* `ptr` is a null pointer or its value represents the
|
| 180 |
-
address of a block of memory allocated by an earlier call to a (possibly
|
| 181 |
-
replaced) `operator new(std::size_t)` or
|
| 182 |
-
`operator new(std::size_t, std::align_val_t)` which has not been
|
| 183 |
-
invalidated by an intervening call to `operator delete`.
|
| 184 |
-
|
| 185 |
-
*Preconditions:* If an implementation has strict pointer
|
| 186 |
-
safety [[basic.stc.dynamic.safety]] then `ptr` is a safely-derived
|
| 187 |
-
pointer.
|
| 188 |
-
|
| 189 |
-
*Preconditions:* If the `alignment` parameter is not present, `ptr` was
|
| 190 |
-
returned by an allocation function without an `alignment` parameter. If
|
| 191 |
-
present, the `alignment` argument is equal to the `alignment` argument
|
| 192 |
-
passed to the allocation function that returned `ptr`. If present, the
|
| 193 |
-
`size` argument is equal to the `size` argument passed to the allocation
|
| 194 |
-
function that returned `ptr`.
|
| 195 |
-
|
| 196 |
*Required behavior:* A call to an `operator delete` with a `size`
|
| 197 |
parameter may be changed to a call to the corresponding
|
| 198 |
`operator delete` without a `size` parameter, without affecting memory
|
| 199 |
allocation.
|
| 200 |
|
|
@@ -220,34 +221,30 @@ reclaimed storage will be allocated by subsequent calls to
|
|
| 220 |
``` cpp
|
| 221 |
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
|
| 222 |
void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 223 |
```
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 226 |
called by the implementation to render the value of `ptr` invalid when
|
| 227 |
the constructor invoked from a nothrow placement version of the
|
| 228 |
*new-expression* throws an exception.
|
| 229 |
|
| 230 |
*Replaceable:* A C++ program may define functions with either of these
|
| 231 |
function signatures, and thereby displace the default versions defined
|
| 232 |
by the C++ standard library.
|
| 233 |
|
| 234 |
-
*Preconditions:* `ptr` is a null pointer or its value represents the
|
| 235 |
-
address of a block of memory allocated by an earlier call to a (possibly
|
| 236 |
-
replaced) `operator new(std::size_t)` or
|
| 237 |
-
`operator new(std::size_t, std::align_val_t)` which has not been
|
| 238 |
-
invalidated by an intervening call to `operator delete`.
|
| 239 |
-
|
| 240 |
-
*Preconditions:* If an implementation has strict pointer
|
| 241 |
-
safety [[basic.stc.dynamic.safety]] then `ptr` is a safely-derived
|
| 242 |
-
pointer.
|
| 243 |
-
|
| 244 |
-
*Preconditions:* If the `alignment` parameter is not present, `ptr` was
|
| 245 |
-
returned by an allocation function without an `alignment` parameter. If
|
| 246 |
-
present, the `alignment` argument is equal to the `alignment` argument
|
| 247 |
-
passed to the allocation function that returned `ptr`.
|
| 248 |
-
|
| 249 |
*Default behavior:* Calls `operator delete(ptr)`, or
|
| 250 |
`operator delete(ptr, alignment)`, respectively.
|
| 251 |
|
| 252 |
#### Array forms <a id="new.delete.array">[[new.delete.array]]</a>
|
| 253 |
|
|
@@ -257,11 +254,11 @@ passed to the allocation function that returned `ptr`.
|
|
| 257 |
```
|
| 258 |
|
| 259 |
*Effects:* The allocation functions [[basic.stc.dynamic.allocation]]
|
| 260 |
called by the array form of a *new-expression*[[expr.new]] to allocate
|
| 261 |
`size` bytes of storage. The second form is called for a type with
|
| 262 |
-
new-extended alignment, and the first form is called otherwise.
|
| 263 |
|
| 264 |
*Replaceable:* A C++ program may define functions with either of these
|
| 265 |
function signatures, and thereby displace the default versions defined
|
| 266 |
by the C++ standard library.
|
| 267 |
|
|
@@ -303,10 +300,23 @@ void operator delete[](void* ptr) noexcept;
|
|
| 303 |
void operator delete[](void* ptr, std::size_t size) noexcept;
|
| 304 |
void operator delete[](void* ptr, std::align_val_t alignment) noexcept;
|
| 305 |
void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 306 |
```
|
| 307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 309 |
called by the array form of a *delete-expression* to render the value of
|
| 310 |
`ptr` invalid.
|
| 311 |
|
| 312 |
*Replaceable:* A C++ program may define functions with any of these
|
|
@@ -316,31 +326,14 @@ by the C++ standard library.
|
|
| 316 |
If a function without a `size` parameter is defined, the program should
|
| 317 |
also define the corresponding function with a `size` parameter. If a
|
| 318 |
function with a `size` parameter is defined, the program shall also
|
| 319 |
define the corresponding version without the `size` parameter.
|
| 320 |
|
| 321 |
-
[*Note 1*: The default behavior below
|
| 322 |
will require replacing both deallocation functions when replacing the
|
| 323 |
allocation function. — *end note*]
|
| 324 |
|
| 325 |
-
*Preconditions:* `ptr` is a null pointer or its value represents the
|
| 326 |
-
address of a block of memory allocated by an earlier call to a (possibly
|
| 327 |
-
replaced) `operator new[](std::size_t)` or
|
| 328 |
-
`operator new[](std::size_t, std::align_val_t)` which has not been
|
| 329 |
-
invalidated by an intervening call to `operator delete[]`.
|
| 330 |
-
|
| 331 |
-
*Preconditions:* If an implementation has strict pointer
|
| 332 |
-
safety [[basic.stc.dynamic.safety]] then `ptr` is a safely-derived
|
| 333 |
-
pointer.
|
| 334 |
-
|
| 335 |
-
*Preconditions:* If the `alignment` parameter is not present, `ptr` was
|
| 336 |
-
returned by an allocation function without an `alignment` parameter. If
|
| 337 |
-
present, the `alignment` argument is equal to the `alignment` argument
|
| 338 |
-
passed to the allocation function that returned `ptr`. If present, the
|
| 339 |
-
`size` argument is equal to the `size` argument passed to the allocation
|
| 340 |
-
function that returned `ptr`.
|
| 341 |
-
|
| 342 |
*Required behavior:* A call to an `operator delete[]` with a `size`
|
| 343 |
parameter may be changed to a call to the corresponding
|
| 344 |
`operator delete[]` without a `size` parameter, without affecting memory
|
| 345 |
allocation.
|
| 346 |
|
|
@@ -357,34 +350,30 @@ function.
|
|
| 357 |
``` cpp
|
| 358 |
void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
|
| 359 |
void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 360 |
```
|
| 361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 363 |
called by the implementation to render the value of `ptr` invalid when
|
| 364 |
the constructor invoked from a nothrow placement version of the array
|
| 365 |
*new-expression* throws an exception.
|
| 366 |
|
| 367 |
*Replaceable:* A C++ program may define functions with either of these
|
| 368 |
function signatures, and thereby displace the default versions defined
|
| 369 |
by the C++ standard library.
|
| 370 |
|
| 371 |
-
*Preconditions:* `ptr` is a null pointer or its value represents the
|
| 372 |
-
address of a block of memory allocated by an earlier call to a (possibly
|
| 373 |
-
replaced) `operator new[](std::size_t)` or
|
| 374 |
-
`operator new[](std::size_t, std::align_val_t)` which has not been
|
| 375 |
-
invalidated by an intervening call to `operator delete[]`.
|
| 376 |
-
|
| 377 |
-
*Preconditions:* If an implementation has strict pointer
|
| 378 |
-
safety [[basic.stc.dynamic.safety]] then `ptr` is a safely-derived
|
| 379 |
-
pointer.
|
| 380 |
-
|
| 381 |
-
*Preconditions:* If the `alignment` parameter is not present, `ptr` was
|
| 382 |
-
returned by an allocation function without an `alignment` parameter. If
|
| 383 |
-
present, the `alignment` argument is equal to the `alignment` argument
|
| 384 |
-
passed to the allocation function that returned `ptr`.
|
| 385 |
-
|
| 386 |
*Default behavior:* Calls `operator delete[](ptr)`, or
|
| 387 |
`operator delete[](ptr, alignment)`, respectively.
|
| 388 |
|
| 389 |
#### Non-allocating forms <a id="new.delete.placement">[[new.delete.placement]]</a>
|
| 390 |
|
|
@@ -424,28 +413,20 @@ Something* p = new (place) Something();
|
|
| 424 |
void operator delete(void* ptr, void*) noexcept;
|
| 425 |
```
|
| 426 |
|
| 427 |
*Effects:* Intentionally performs no action.
|
| 428 |
|
| 429 |
-
*Preconditions:* If an implementation has strict pointer
|
| 430 |
-
safety [[basic.stc.dynamic.safety]] then `ptr` is a safely-derived
|
| 431 |
-
pointer.
|
| 432 |
-
|
| 433 |
*Remarks:* Default function called when any part of the initialization
|
| 434 |
in a placement *new-expression* that invokes the library’s non-array
|
| 435 |
placement operator new terminates by throwing an exception [[expr.new]].
|
| 436 |
|
| 437 |
``` cpp
|
| 438 |
void operator delete[](void* ptr, void*) noexcept;
|
| 439 |
```
|
| 440 |
|
| 441 |
*Effects:* Intentionally performs no action.
|
| 442 |
|
| 443 |
-
*Preconditions:* If an implementation has strict pointer
|
| 444 |
-
safety [[basic.stc.dynamic.safety]] then `ptr` is a safely-derived
|
| 445 |
-
pointer.
|
| 446 |
-
|
| 447 |
*Remarks:* Default function called when any part of the initialization
|
| 448 |
in a placement *new-expression* that invokes the library’s array
|
| 449 |
placement operator new terminates by throwing an exception [[expr.new]].
|
| 450 |
|
| 451 |
#### Data races <a id="new.delete.dataraces">[[new.delete.dataraces]]</a>
|
|
@@ -543,11 +524,11 @@ new_handler set_new_handler(new_handler new_p) noexcept;
|
|
| 543 |
new_handler get_new_handler() noexcept;
|
| 544 |
```
|
| 545 |
|
| 546 |
*Returns:* The current `new_handler`.
|
| 547 |
|
| 548 |
-
[*Note 1*: This
|
| 549 |
|
| 550 |
### Pointer optimization barrier <a id="ptr.launder">[[ptr.launder]]</a>
|
| 551 |
|
| 552 |
``` cpp
|
| 553 |
template<class T> [[nodiscard]] constexpr T* launder(T* p) noexcept;
|
|
@@ -556,22 +537,18 @@ template<class T> [[nodiscard]] constexpr T* launder(T* p) noexcept;
|
|
| 556 |
*Mandates:* `!is_function_v<T> && !is_void_v<T>` is `true`.
|
| 557 |
|
| 558 |
*Preconditions:* `p` represents the address *A* of a byte in memory. An
|
| 559 |
object *X* that is within its lifetime [[basic.life]] and whose type is
|
| 560 |
similar [[conv.qual]] to `T` is located at the address *A*. All bytes of
|
| 561 |
-
storage that would be reachable through the result
|
| 562 |
-
`p`
|
| 563 |
|
| 564 |
-
*Returns:* A value of type `T*` that points to
|
| 565 |
|
| 566 |
*Remarks:* An invocation of this function may be used in a core constant
|
| 567 |
-
expression
|
| 568 |
-
|
| 569 |
-
pointer value that points to an object *Y* if there is an object *Z*,
|
| 570 |
-
pointer-interconvertible with *Y*, such that *b* is within the storage
|
| 571 |
-
occupied by *Z*, or the immediately-enclosing array object if *Z* is an
|
| 572 |
-
array element.
|
| 573 |
|
| 574 |
[*Note 1*: If a new object is created in storage occupied by an
|
| 575 |
existing object of the same type, a pointer to the original object can
|
| 576 |
be used to refer to the new object unless its complete object is a const
|
| 577 |
object or it is a base class subobject; in the latter cases, this
|
|
|
|
| 1 |
## Dynamic memory management <a id="support.dynamic">[[support.dynamic]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="support.dynamic.general">[[support.dynamic.general]]</a>
|
| 4 |
+
|
| 5 |
The header `<new>` defines several functions that manage the allocation
|
| 6 |
of dynamic storage in a program. It also defines components for
|
| 7 |
reporting storage management errors.
|
| 8 |
|
| 9 |
### Header `<new>` synopsis <a id="new.syn">[[new.syn]]</a>
|
| 10 |
|
| 11 |
``` cpp
|
| 12 |
+
// all freestanding
|
| 13 |
namespace std {
|
| 14 |
// [alloc.errors], storage allocation errors
|
| 15 |
class bad_alloc;
|
| 16 |
class bad_array_new_length;
|
| 17 |
|
|
|
|
| 76 |
void operator delete[](void* ptr, void*) noexcept;
|
| 77 |
```
|
| 78 |
|
| 79 |
### Storage allocation and deallocation <a id="new.delete">[[new.delete]]</a>
|
| 80 |
|
| 81 |
+
#### General <a id="new.delete.general">[[new.delete.general]]</a>
|
| 82 |
+
|
| 83 |
Except where otherwise specified, the provisions of
|
| 84 |
[[basic.stc.dynamic]] apply to the library versions of `operator new`
|
| 85 |
and `operator
|
| 86 |
delete`. If the value of an alignment argument passed to any of these
|
| 87 |
functions is not a valid alignment value, the behavior is undefined.
|
|
|
|
| 162 |
void operator delete(void* ptr, std::size_t size) noexcept;
|
| 163 |
void operator delete(void* ptr, std::align_val_t alignment) noexcept;
|
| 164 |
void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 165 |
```
|
| 166 |
|
| 167 |
+
*Preconditions:* `ptr` is a null pointer or its value represents the
|
| 168 |
+
address of a block of memory allocated by an earlier call to a (possibly
|
| 169 |
+
replaced) `operator new(std::size_t)` or
|
| 170 |
+
`operator new(std::size_t, std::align_val_t)` which has not been
|
| 171 |
+
invalidated by an intervening call to `operator delete`.
|
| 172 |
+
|
| 173 |
+
If the `alignment` parameter is not present, `ptr` was returned by an
|
| 174 |
+
allocation function without an `alignment` parameter. If present, the
|
| 175 |
+
`alignment` argument is equal to the `alignment` argument passed to the
|
| 176 |
+
allocation function that returned `ptr`. If present, the `size` argument
|
| 177 |
+
is equal to the `size` argument passed to the allocation function that
|
| 178 |
+
returned `ptr`.
|
| 179 |
+
|
| 180 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 181 |
called by a *delete-expression*[[expr.delete]] to render the value of
|
| 182 |
`ptr` invalid.
|
| 183 |
|
| 184 |
*Replaceable:* A C++ program may define functions with any of these
|
|
|
|
| 188 |
If a function without a `size` parameter is defined, the program should
|
| 189 |
also define the corresponding function with a `size` parameter. If a
|
| 190 |
function with a `size` parameter is defined, the program shall also
|
| 191 |
define the corresponding version without the `size` parameter.
|
| 192 |
|
| 193 |
+
[*Note 1*: The default behavior below might change in the future, which
|
| 194 |
will require replacing both deallocation functions when replacing the
|
| 195 |
allocation function. — *end note*]
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
*Required behavior:* A call to an `operator delete` with a `size`
|
| 198 |
parameter may be changed to a call to the corresponding
|
| 199 |
`operator delete` without a `size` parameter, without affecting memory
|
| 200 |
allocation.
|
| 201 |
|
|
|
|
| 221 |
``` cpp
|
| 222 |
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
|
| 223 |
void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 224 |
```
|
| 225 |
|
| 226 |
+
*Preconditions:* `ptr` is a null pointer or its value represents the
|
| 227 |
+
address of a block of memory allocated by an earlier call to a (possibly
|
| 228 |
+
replaced) `operator new(std::size_t)` or
|
| 229 |
+
`operator new(std::size_t, std::align_val_t)` which has not been
|
| 230 |
+
invalidated by an intervening call to `operator delete`.
|
| 231 |
+
|
| 232 |
+
If the `alignment` parameter is not present, `ptr` was returned by an
|
| 233 |
+
allocation function without an `alignment` parameter. If present, the
|
| 234 |
+
`alignment` argument is equal to the `alignment` argument passed to the
|
| 235 |
+
allocation function that returned `ptr`.
|
| 236 |
+
|
| 237 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 238 |
called by the implementation to render the value of `ptr` invalid when
|
| 239 |
the constructor invoked from a nothrow placement version of the
|
| 240 |
*new-expression* throws an exception.
|
| 241 |
|
| 242 |
*Replaceable:* A C++ program may define functions with either of these
|
| 243 |
function signatures, and thereby displace the default versions defined
|
| 244 |
by the C++ standard library.
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
*Default behavior:* Calls `operator delete(ptr)`, or
|
| 247 |
`operator delete(ptr, alignment)`, respectively.
|
| 248 |
|
| 249 |
#### Array forms <a id="new.delete.array">[[new.delete.array]]</a>
|
| 250 |
|
|
|
|
| 254 |
```
|
| 255 |
|
| 256 |
*Effects:* The allocation functions [[basic.stc.dynamic.allocation]]
|
| 257 |
called by the array form of a *new-expression*[[expr.new]] to allocate
|
| 258 |
`size` bytes of storage. The second form is called for a type with
|
| 259 |
+
new-extended alignment, and the first form is called otherwise.[^31]
|
| 260 |
|
| 261 |
*Replaceable:* A C++ program may define functions with either of these
|
| 262 |
function signatures, and thereby displace the default versions defined
|
| 263 |
by the C++ standard library.
|
| 264 |
|
|
|
|
| 300 |
void operator delete[](void* ptr, std::size_t size) noexcept;
|
| 301 |
void operator delete[](void* ptr, std::align_val_t alignment) noexcept;
|
| 302 |
void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 303 |
```
|
| 304 |
|
| 305 |
+
*Preconditions:* `ptr` is a null pointer or its value represents the
|
| 306 |
+
address of a block of memory allocated by an earlier call to a (possibly
|
| 307 |
+
replaced) `operator new[](std::size_t)` or
|
| 308 |
+
`operator new[](std::size_t, std::align_val_t)` which has not been
|
| 309 |
+
invalidated by an intervening call to `operator delete[]`.
|
| 310 |
+
|
| 311 |
+
If the `alignment` parameter is not present, `ptr` was returned by an
|
| 312 |
+
allocation function without an `alignment` parameter. If present, the
|
| 313 |
+
`alignment` argument is equal to the `alignment` argument passed to the
|
| 314 |
+
allocation function that returned `ptr`. If present, the `size` argument
|
| 315 |
+
is equal to the `size` argument passed to the allocation function that
|
| 316 |
+
returned `ptr`.
|
| 317 |
+
|
| 318 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 319 |
called by the array form of a *delete-expression* to render the value of
|
| 320 |
`ptr` invalid.
|
| 321 |
|
| 322 |
*Replaceable:* A C++ program may define functions with any of these
|
|
|
|
| 326 |
If a function without a `size` parameter is defined, the program should
|
| 327 |
also define the corresponding function with a `size` parameter. If a
|
| 328 |
function with a `size` parameter is defined, the program shall also
|
| 329 |
define the corresponding version without the `size` parameter.
|
| 330 |
|
| 331 |
+
[*Note 1*: The default behavior below might change in the future, which
|
| 332 |
will require replacing both deallocation functions when replacing the
|
| 333 |
allocation function. — *end note*]
|
| 334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
*Required behavior:* A call to an `operator delete[]` with a `size`
|
| 336 |
parameter may be changed to a call to the corresponding
|
| 337 |
`operator delete[]` without a `size` parameter, without affecting memory
|
| 338 |
allocation.
|
| 339 |
|
|
|
|
| 350 |
``` cpp
|
| 351 |
void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
|
| 352 |
void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 353 |
```
|
| 354 |
|
| 355 |
+
*Preconditions:* `ptr` is a null pointer or its value represents the
|
| 356 |
+
address of a block of memory allocated by an earlier call to a (possibly
|
| 357 |
+
replaced) `operator new[](std::size_t)` or
|
| 358 |
+
`operator new[](std::size_t, std::align_val_t)` which has not been
|
| 359 |
+
invalidated by an intervening call to `operator delete[]`.
|
| 360 |
+
|
| 361 |
+
If the `alignment` parameter is not present, `ptr` was returned by an
|
| 362 |
+
allocation function without an `alignment` parameter. If present, the
|
| 363 |
+
`alignment` argument is equal to the `alignment` argument passed to the
|
| 364 |
+
allocation function that returned `ptr`.
|
| 365 |
+
|
| 366 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 367 |
called by the implementation to render the value of `ptr` invalid when
|
| 368 |
the constructor invoked from a nothrow placement version of the array
|
| 369 |
*new-expression* throws an exception.
|
| 370 |
|
| 371 |
*Replaceable:* A C++ program may define functions with either of these
|
| 372 |
function signatures, and thereby displace the default versions defined
|
| 373 |
by the C++ standard library.
|
| 374 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
*Default behavior:* Calls `operator delete[](ptr)`, or
|
| 376 |
`operator delete[](ptr, alignment)`, respectively.
|
| 377 |
|
| 378 |
#### Non-allocating forms <a id="new.delete.placement">[[new.delete.placement]]</a>
|
| 379 |
|
|
|
|
| 413 |
void operator delete(void* ptr, void*) noexcept;
|
| 414 |
```
|
| 415 |
|
| 416 |
*Effects:* Intentionally performs no action.
|
| 417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
*Remarks:* Default function called when any part of the initialization
|
| 419 |
in a placement *new-expression* that invokes the library’s non-array
|
| 420 |
placement operator new terminates by throwing an exception [[expr.new]].
|
| 421 |
|
| 422 |
``` cpp
|
| 423 |
void operator delete[](void* ptr, void*) noexcept;
|
| 424 |
```
|
| 425 |
|
| 426 |
*Effects:* Intentionally performs no action.
|
| 427 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
*Remarks:* Default function called when any part of the initialization
|
| 429 |
in a placement *new-expression* that invokes the library’s array
|
| 430 |
placement operator new terminates by throwing an exception [[expr.new]].
|
| 431 |
|
| 432 |
#### Data races <a id="new.delete.dataraces">[[new.delete.dataraces]]</a>
|
|
|
|
| 524 |
new_handler get_new_handler() noexcept;
|
| 525 |
```
|
| 526 |
|
| 527 |
*Returns:* The current `new_handler`.
|
| 528 |
|
| 529 |
+
[*Note 1*: This can be a null pointer value. — *end note*]
|
| 530 |
|
| 531 |
### Pointer optimization barrier <a id="ptr.launder">[[ptr.launder]]</a>
|
| 532 |
|
| 533 |
``` cpp
|
| 534 |
template<class T> [[nodiscard]] constexpr T* launder(T* p) noexcept;
|
|
|
|
| 537 |
*Mandates:* `!is_function_v<T> && !is_void_v<T>` is `true`.
|
| 538 |
|
| 539 |
*Preconditions:* `p` represents the address *A* of a byte in memory. An
|
| 540 |
object *X* that is within its lifetime [[basic.life]] and whose type is
|
| 541 |
similar [[conv.qual]] to `T` is located at the address *A*. All bytes of
|
| 542 |
+
storage that would be reachable through [[basic.compound]] the result
|
| 543 |
+
are reachable through `p`.
|
| 544 |
|
| 545 |
+
*Returns:* A value of type `T*` that points to *X*.
|
| 546 |
|
| 547 |
*Remarks:* An invocation of this function may be used in a core constant
|
| 548 |
+
expression if and only if the (converted) value of its argument may be
|
| 549 |
+
used in place of the function invocation.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
|
| 551 |
[*Note 1*: If a new object is created in storage occupied by an
|
| 552 |
existing object of the same type, a pointer to the original object can
|
| 553 |
be used to refer to the new object unless its complete object is a const
|
| 554 |
object or it is a base class subobject; in the latter cases, this
|