tmp/tmp_frqdp3v/{from.md → to.md}
RENAMED
|
@@ -34,46 +34,45 @@ namespace std {
|
|
| 34 |
using new_handler = void (*)();
|
| 35 |
new_handler get_new_handler() noexcept;
|
| 36 |
new_handler set_new_handler(new_handler new_p) noexcept;
|
| 37 |
|
| 38 |
// [ptr.launder], pointer optimization barrier
|
| 39 |
-
template<class T>
|
| 40 |
|
| 41 |
// [hardware.interference], hardware interference size
|
| 42 |
inline constexpr size_t hardware_destructive_interference_size = implementation-defined{};
|
| 43 |
inline constexpr size_t hardware_constructive_interference_size = implementation-defined{};
|
| 44 |
}
|
| 45 |
|
| 46 |
// [new.delete], storage allocation and deallocation
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
const std::nothrow_t&) noexcept;
|
| 52 |
|
| 53 |
void operator delete(void* ptr) noexcept;
|
| 54 |
void operator delete(void* ptr, std::size_t size) noexcept;
|
| 55 |
void operator delete(void* ptr, std::align_val_t alignment) noexcept;
|
| 56 |
void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 57 |
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
|
| 58 |
void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
const std::nothrow_t&) noexcept;
|
| 65 |
|
| 66 |
void operator delete[](void* ptr) noexcept;
|
| 67 |
void operator delete[](void* ptr, std::size_t size) noexcept;
|
| 68 |
void operator delete[](void* ptr, std::align_val_t alignment) noexcept;
|
| 69 |
void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 70 |
void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
|
| 71 |
void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
void operator delete (void* ptr, void*) noexcept;
|
| 76 |
void operator delete[](void* ptr, void*) noexcept;
|
| 77 |
```
|
| 78 |
|
| 79 |
### Storage allocation and deallocation <a id="new.delete">[[new.delete]]</a>
|
|
@@ -84,26 +83,37 @@ 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.
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
#### Single-object forms <a id="new.delete.single">[[new.delete.single]]</a>
|
| 90 |
|
| 91 |
``` cpp
|
| 92 |
-
|
| 93 |
-
|
| 94 |
```
|
| 95 |
|
| 96 |
*Effects:* The allocation functions [[basic.stc.dynamic.allocation]]
|
| 97 |
called by a *new-expression*[[expr.new]] to allocate `size` bytes of
|
| 98 |
storage. The second form is called for a type with new-extended
|
| 99 |
alignment, and the first form is called otherwise.
|
| 100 |
|
| 101 |
-
*Replaceable:* A C++ program may define functions with either of these
|
| 102 |
-
function signatures, and thereby displace the default versions defined
|
| 103 |
-
by the C++ standard library.
|
| 104 |
-
|
| 105 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 106 |
storage [[basic.stc.dynamic]], or else throw a `bad_alloc` exception.
|
| 107 |
This requirement is binding on any replacement versions of these
|
| 108 |
functions.
|
| 109 |
|
|
@@ -120,24 +130,21 @@ functions.
|
|
| 120 |
function [[new.handler]]. If the called function returns, the loop
|
| 121 |
repeats.
|
| 122 |
- The loop terminates when an attempt to allocate the requested storage
|
| 123 |
is successful or when a called `new_handler` function does not return.
|
| 124 |
|
|
|
|
|
|
|
| 125 |
``` cpp
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
const std::nothrow_t&) noexcept;
|
| 129 |
```
|
| 130 |
|
| 131 |
*Effects:* Same as above, except that these are called by a placement
|
| 132 |
version of a *new-expression* when a C++ program prefers a null pointer
|
| 133 |
result as an error indication, instead of a `bad_alloc` exception.
|
| 134 |
|
| 135 |
-
*Replaceable:* A C++ program may define functions with either of these
|
| 136 |
-
function signatures, and thereby displace the default versions defined
|
| 137 |
-
by the C++ standard library.
|
| 138 |
-
|
| 139 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 140 |
storage [[basic.stc.dynamic]], or else return a null pointer. Each of
|
| 141 |
these nothrow versions of `operator new` returns a pointer obtained as
|
| 142 |
if acquired from the (possibly replaced) corresponding non-placement
|
| 143 |
function. This requirement is binding on any replacement versions of
|
|
@@ -155,10 +162,12 @@ T* p1 = new T; // throws bad_alloc if it fails
|
|
| 155 |
T* p2 = new(nothrow) T; // returns nullptr if it fails
|
| 156 |
```
|
| 157 |
|
| 158 |
— *end example*]
|
| 159 |
|
|
|
|
|
|
|
| 160 |
``` cpp
|
| 161 |
void operator delete(void* ptr) noexcept;
|
| 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;
|
|
@@ -179,46 +188,43 @@ 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
|
| 185 |
-
function signatures, and thereby displace the default versions defined
|
| 186 |
-
by the C++ standard library.
|
| 187 |
-
|
| 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 |
|
| 202 |
-
[*Note
|
| 203 |
`operator delete(void* ptr, std::size_t size)` to simply call
|
| 204 |
`operator delete(ptr)`. — *end note*]
|
| 205 |
|
| 206 |
*Default behavior:* The functions that have a `size` parameter forward
|
| 207 |
their other parameters to the corresponding function without a `size`
|
| 208 |
parameter.
|
| 209 |
|
| 210 |
-
[*Note
|
| 211 |
paragraph. — *end note*]
|
| 212 |
|
| 213 |
*Default behavior:* If `ptr` is null, does nothing. Otherwise, reclaims
|
| 214 |
the storage allocated by the earlier call to `operator new`.
|
| 215 |
|
| 216 |
*Remarks:* It is unspecified under what conditions part or all of such
|
| 217 |
reclaimed storage will be allocated by subsequent calls to
|
| 218 |
`operator new` or any of `aligned_alloc`, `calloc`, `malloc`, or
|
| 219 |
-
`realloc`, declared in `<cstdlib>`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 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 |
```
|
|
@@ -237,54 +243,45 @@ allocation function that returned `ptr`.
|
|
| 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 |
|
| 251 |
``` cpp
|
| 252 |
-
|
| 253 |
-
|
| 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 |
-
|
| 265 |
*Required behavior:* Same as for the corresponding single-object forms.
|
| 266 |
This requirement is binding on any replacement versions of these
|
| 267 |
functions.
|
| 268 |
|
| 269 |
*Default behavior:* Returns `operator new(size)`, or
|
| 270 |
`operator new(size, alignment)`, respectively.
|
| 271 |
|
|
|
|
|
|
|
| 272 |
``` cpp
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
const std::nothrow_t&) noexcept;
|
| 276 |
```
|
| 277 |
|
| 278 |
*Effects:* Same as above, except that these are called by a placement
|
| 279 |
version of a *new-expression* when a C++ program prefers a null pointer
|
| 280 |
result as an error indication, instead of a `bad_alloc` exception.
|
| 281 |
|
| 282 |
-
*Replaceable:* A C++ program may define functions with either of these
|
| 283 |
-
function signatures, and thereby displace the default versions defined
|
| 284 |
-
by the C++ standard library.
|
| 285 |
-
|
| 286 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 287 |
storage [[basic.stc.dynamic]], or else return a null pointer. Each of
|
| 288 |
these nothrow versions of `operator new[]` returns a pointer obtained as
|
| 289 |
if acquired from the (possibly replaced) corresponding non-placement
|
| 290 |
function. This requirement is binding on any replacement versions of
|
|
@@ -293,10 +290,12 @@ these functions.
|
|
| 293 |
*Default behavior:* Calls `operator new[](size)`, or
|
| 294 |
`operator new[](size, alignment)`, respectively. If the call returns
|
| 295 |
normally, returns the result of that call. Otherwise, returns a null
|
| 296 |
pointer.
|
| 297 |
|
|
|
|
|
|
|
| 298 |
``` cpp
|
| 299 |
void operator delete[](void* ptr) noexcept;
|
| 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;
|
|
@@ -317,38 +316,36 @@ 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
|
| 323 |
-
function signatures, and thereby displace the default versions defined
|
| 324 |
-
by the C++ standard library.
|
| 325 |
-
|
| 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 |
|
| 340 |
-
[*Note
|
| 341 |
`operator delete[](void* ptr, std::size_t size)` to simply call
|
| 342 |
`operator delete[](ptr)`. — *end note*]
|
| 343 |
|
| 344 |
*Default behavior:* The functions that have a `size` parameter forward
|
| 345 |
their other parameters to the corresponding function without a `size`
|
| 346 |
parameter. The functions that do not have a `size` parameter forward
|
| 347 |
their parameters to the corresponding `operator delete` (single-object)
|
| 348 |
function.
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
@@ -366,26 +363,24 @@ allocation function that returned `ptr`.
|
|
| 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 |
|
| 380 |
These functions are reserved; a C++ program may not define functions
|
| 381 |
that displace the versions in the C++ standard library [[constraints]].
|
| 382 |
The provisions of [[basic.stc.dynamic]] do not apply to these reserved
|
| 383 |
placement forms of `operator new` and `operator delete`.
|
| 384 |
|
| 385 |
``` cpp
|
| 386 |
-
|
| 387 |
```
|
| 388 |
|
| 389 |
*Returns:* `ptr`.
|
| 390 |
|
| 391 |
*Remarks:* Intentionally performs no other action.
|
|
@@ -400,11 +395,11 @@ Something* p = new (place) Something();
|
|
| 400 |
```
|
| 401 |
|
| 402 |
— *end example*]
|
| 403 |
|
| 404 |
``` cpp
|
| 405 |
-
|
| 406 |
```
|
| 407 |
|
| 408 |
*Returns:* `ptr`.
|
| 409 |
|
| 410 |
*Remarks:* Intentionally performs no other action.
|
|
@@ -449,20 +444,20 @@ before [[intro.multithread]] the next allocation (if any) in this order.
|
|
| 449 |
``` cpp
|
| 450 |
namespace std {
|
| 451 |
class bad_alloc : public exception {
|
| 452 |
public:
|
| 453 |
// see [exception] for the specification of the special member functions
|
| 454 |
-
const char* what() const noexcept override;
|
| 455 |
};
|
| 456 |
}
|
| 457 |
```
|
| 458 |
|
| 459 |
The class `bad_alloc` defines the type of objects thrown as exceptions
|
| 460 |
by the implementation to report a failure to allocate storage.
|
| 461 |
|
| 462 |
``` cpp
|
| 463 |
-
const char* what() const noexcept override;
|
| 464 |
```
|
| 465 |
|
| 466 |
*Returns:* An *implementation-defined* NTBS.
|
| 467 |
|
| 468 |
#### Class `bad_array_new_length` <a id="new.badlength">[[new.badlength]]</a>
|
|
@@ -470,22 +465,22 @@ const char* what() const noexcept override;
|
|
| 470 |
``` cpp
|
| 471 |
namespace std {
|
| 472 |
class bad_array_new_length : public bad_alloc {
|
| 473 |
public:
|
| 474 |
// see [exception] for the specification of the special member functions
|
| 475 |
-
const char* what() const noexcept override;
|
| 476 |
};
|
| 477 |
}
|
| 478 |
```
|
| 479 |
|
| 480 |
The class `bad_array_new_length` defines the type of objects thrown as
|
| 481 |
exceptions by the implementation to report an attempt to allocate an
|
| 482 |
array of size less than zero or greater than an *implementation-defined*
|
| 483 |
limit [[expr.new]].
|
| 484 |
|
| 485 |
``` cpp
|
| 486 |
-
const char* what() const noexcept override;
|
| 487 |
```
|
| 488 |
|
| 489 |
*Returns:* An *implementation-defined* NTBS.
|
| 490 |
|
| 491 |
#### Type `new_handler` <a id="new.handler">[[new.handler]]</a>
|
|
@@ -529,11 +524,11 @@ new_handler get_new_handler() noexcept;
|
|
| 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>
|
| 535 |
```
|
| 536 |
|
| 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
|
|
|
|
| 34 |
using new_handler = void (*)();
|
| 35 |
new_handler get_new_handler() noexcept;
|
| 36 |
new_handler set_new_handler(new_handler new_p) noexcept;
|
| 37 |
|
| 38 |
// [ptr.launder], pointer optimization barrier
|
| 39 |
+
template<class T> constexpr T* launder(T* p) noexcept;
|
| 40 |
|
| 41 |
// [hardware.interference], hardware interference size
|
| 42 |
inline constexpr size_t hardware_destructive_interference_size = implementation-defined{};
|
| 43 |
inline constexpr size_t hardware_constructive_interference_size = implementation-defined{};
|
| 44 |
}
|
| 45 |
|
| 46 |
// [new.delete], storage allocation and deallocation
|
| 47 |
+
void* operator new(std::size_t size);
|
| 48 |
+
void* operator new(std::size_t size, std::align_val_t alignment);
|
| 49 |
+
void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
|
| 50 |
+
void* operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
|
|
|
| 51 |
|
| 52 |
void operator delete(void* ptr) noexcept;
|
| 53 |
void operator delete(void* ptr, std::size_t size) noexcept;
|
| 54 |
void operator delete(void* ptr, std::align_val_t alignment) noexcept;
|
| 55 |
void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 56 |
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
|
| 57 |
void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 58 |
|
| 59 |
+
void* operator new[](std::size_t size);
|
| 60 |
+
void* operator new[](std::size_t size, std::align_val_t alignment);
|
| 61 |
+
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;
|
| 62 |
+
void* operator new[](std::size_t size, std::align_val_t alignment,
|
| 63 |
const std::nothrow_t&) noexcept;
|
| 64 |
|
| 65 |
void operator delete[](void* ptr) noexcept;
|
| 66 |
void operator delete[](void* ptr, std::size_t size) noexcept;
|
| 67 |
void operator delete[](void* ptr, std::align_val_t alignment) noexcept;
|
| 68 |
void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
| 69 |
void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
|
| 70 |
void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 71 |
|
| 72 |
+
constexpr void* operator new (std::size_t size, void* ptr) noexcept;
|
| 73 |
+
constexpr void* operator new[](std::size_t size, void* ptr) noexcept;
|
| 74 |
void operator delete (void* ptr, void*) noexcept;
|
| 75 |
void operator delete[](void* ptr, void*) noexcept;
|
| 76 |
```
|
| 77 |
|
| 78 |
### Storage allocation and deallocation <a id="new.delete">[[new.delete]]</a>
|
|
|
|
| 83 |
[[basic.stc.dynamic]] apply to the library versions of `operator new`
|
| 84 |
and `operator
|
| 85 |
delete`. If the value of an alignment argument passed to any of these
|
| 86 |
functions is not a valid alignment value, the behavior is undefined.
|
| 87 |
|
| 88 |
+
On freestanding implementations, it is *implementation-defined* whether
|
| 89 |
+
the default versions of the replaceable global allocation functions
|
| 90 |
+
satisfy the required behaviors described in [[new.delete.single]] and
|
| 91 |
+
[[new.delete.array]].
|
| 92 |
+
|
| 93 |
+
[*Note 1*: A freestanding implementation’s default versions of the
|
| 94 |
+
replaceable global allocation functions can cause undefined behavior
|
| 95 |
+
when invoked. During constant evaluation, the behaviors of those default
|
| 96 |
+
versions are irrelevant, as those calls are omitted
|
| 97 |
+
[[expr.new]]. — *end note*]
|
| 98 |
+
|
| 99 |
+
*Recommended practice:* If any of the default versions of the
|
| 100 |
+
replaceable global allocation functions meet the requirements of a
|
| 101 |
+
hosted implementation, they all should.
|
| 102 |
+
|
| 103 |
#### Single-object forms <a id="new.delete.single">[[new.delete.single]]</a>
|
| 104 |
|
| 105 |
``` cpp
|
| 106 |
+
void* operator new(std::size_t size);
|
| 107 |
+
void* operator new(std::size_t size, std::align_val_t alignment);
|
| 108 |
```
|
| 109 |
|
| 110 |
*Effects:* The allocation functions [[basic.stc.dynamic.allocation]]
|
| 111 |
called by a *new-expression*[[expr.new]] to allocate `size` bytes of
|
| 112 |
storage. The second form is called for a type with new-extended
|
| 113 |
alignment, and the first form is called otherwise.
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 116 |
storage [[basic.stc.dynamic]], or else throw a `bad_alloc` exception.
|
| 117 |
This requirement is binding on any replacement versions of these
|
| 118 |
functions.
|
| 119 |
|
|
|
|
| 130 |
function [[new.handler]]. If the called function returns, the loop
|
| 131 |
repeats.
|
| 132 |
- The loop terminates when an attempt to allocate the requested storage
|
| 133 |
is successful or when a called `new_handler` function does not return.
|
| 134 |
|
| 135 |
+
*Remarks:* This function is replaceable [[term.replaceable.function]].
|
| 136 |
+
|
| 137 |
``` cpp
|
| 138 |
+
void* operator new(std::size_t size, const std::nothrow_t&) noexcept;
|
| 139 |
+
void* operator new(std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
|
|
|
| 140 |
```
|
| 141 |
|
| 142 |
*Effects:* Same as above, except that these are called by a placement
|
| 143 |
version of a *new-expression* when a C++ program prefers a null pointer
|
| 144 |
result as an error indication, instead of a `bad_alloc` exception.
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 147 |
storage [[basic.stc.dynamic]], or else return a null pointer. Each of
|
| 148 |
these nothrow versions of `operator new` returns a pointer obtained as
|
| 149 |
if acquired from the (possibly replaced) corresponding non-placement
|
| 150 |
function. This requirement is binding on any replacement versions of
|
|
|
|
| 162 |
T* p2 = new(nothrow) T; // returns nullptr if it fails
|
| 163 |
```
|
| 164 |
|
| 165 |
— *end example*]
|
| 166 |
|
| 167 |
+
*Remarks:* This function is replaceable [[term.replaceable.function]].
|
| 168 |
+
|
| 169 |
``` cpp
|
| 170 |
void operator delete(void* ptr) noexcept;
|
| 171 |
void operator delete(void* ptr, std::size_t size) noexcept;
|
| 172 |
void operator delete(void* ptr, std::align_val_t alignment) noexcept;
|
| 173 |
void operator delete(void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
|
|
|
| 188 |
|
| 189 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 190 |
called by a *delete-expression*[[expr.delete]] to render the value of
|
| 191 |
`ptr` invalid.
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
*Required behavior:* A call to an `operator delete` with a `size`
|
| 194 |
parameter may be changed to a call to the corresponding
|
| 195 |
`operator delete` without a `size` parameter, without affecting memory
|
| 196 |
allocation.
|
| 197 |
|
| 198 |
+
[*Note 1*: A conforming implementation is for
|
| 199 |
`operator delete(void* ptr, std::size_t size)` to simply call
|
| 200 |
`operator delete(ptr)`. — *end note*]
|
| 201 |
|
| 202 |
*Default behavior:* The functions that have a `size` parameter forward
|
| 203 |
their other parameters to the corresponding function without a `size`
|
| 204 |
parameter.
|
| 205 |
|
| 206 |
+
[*Note 2*: See the note in the below *Remarks:*
|
| 207 |
paragraph. — *end note*]
|
| 208 |
|
| 209 |
*Default behavior:* If `ptr` is null, does nothing. Otherwise, reclaims
|
| 210 |
the storage allocated by the earlier call to `operator new`.
|
| 211 |
|
| 212 |
*Remarks:* It is unspecified under what conditions part or all of such
|
| 213 |
reclaimed storage will be allocated by subsequent calls to
|
| 214 |
`operator new` or any of `aligned_alloc`, `calloc`, `malloc`, or
|
| 215 |
+
`realloc`, declared in `<cstdlib>`. This function is
|
| 216 |
+
replaceable [[term.replaceable.function]]. If a replacement function
|
| 217 |
+
without a `size` parameter is defined by the program, the program should
|
| 218 |
+
also define the corresponding function with a `size` parameter. If a
|
| 219 |
+
replacement function with a `size` parameter is defined by the program,
|
| 220 |
+
the program shall also define the corresponding version without the
|
| 221 |
+
`size` parameter.
|
| 222 |
+
|
| 223 |
+
[*Note 3*: The default behavior above might change in the future, which
|
| 224 |
+
will require replacing both deallocation functions when replacing the
|
| 225 |
+
allocation function. — *end note*]
|
| 226 |
|
| 227 |
``` cpp
|
| 228 |
void operator delete(void* ptr, const std::nothrow_t&) noexcept;
|
| 229 |
void operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 230 |
```
|
|
|
|
| 243 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 244 |
called by the implementation to render the value of `ptr` invalid when
|
| 245 |
the constructor invoked from a nothrow placement version of the
|
| 246 |
*new-expression* throws an exception.
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
*Default behavior:* Calls `operator delete(ptr)`, or
|
| 249 |
`operator delete(ptr, alignment)`, respectively.
|
| 250 |
|
| 251 |
+
*Remarks:* This function is replaceable [[term.replaceable.function]].
|
| 252 |
+
|
| 253 |
#### Array forms <a id="new.delete.array">[[new.delete.array]]</a>
|
| 254 |
|
| 255 |
``` cpp
|
| 256 |
+
void* operator new[](std::size_t size);
|
| 257 |
+
void* operator new[](std::size_t size, std::align_val_t alignment);
|
| 258 |
```
|
| 259 |
|
| 260 |
*Effects:* The allocation functions [[basic.stc.dynamic.allocation]]
|
| 261 |
called by the array form of a *new-expression*[[expr.new]] to allocate
|
| 262 |
`size` bytes of storage. The second form is called for a type with
|
| 263 |
new-extended alignment, and the first form is called otherwise.[^31]
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
*Required behavior:* Same as for the corresponding single-object forms.
|
| 266 |
This requirement is binding on any replacement versions of these
|
| 267 |
functions.
|
| 268 |
|
| 269 |
*Default behavior:* Returns `operator new(size)`, or
|
| 270 |
`operator new(size, alignment)`, respectively.
|
| 271 |
|
| 272 |
+
*Remarks:* This function is replaceable [[term.replaceable.function]].
|
| 273 |
+
|
| 274 |
``` cpp
|
| 275 |
+
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept;
|
| 276 |
+
void* operator new[](std::size_t size, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
|
|
|
| 277 |
```
|
| 278 |
|
| 279 |
*Effects:* Same as above, except that these are called by a placement
|
| 280 |
version of a *new-expression* when a C++ program prefers a null pointer
|
| 281 |
result as an error indication, instead of a `bad_alloc` exception.
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
*Required behavior:* Return a non-null pointer to suitably aligned
|
| 284 |
storage [[basic.stc.dynamic]], or else return a null pointer. Each of
|
| 285 |
these nothrow versions of `operator new[]` returns a pointer obtained as
|
| 286 |
if acquired from the (possibly replaced) corresponding non-placement
|
| 287 |
function. This requirement is binding on any replacement versions of
|
|
|
|
| 290 |
*Default behavior:* Calls `operator new[](size)`, or
|
| 291 |
`operator new[](size, alignment)`, respectively. If the call returns
|
| 292 |
normally, returns the result of that call. Otherwise, returns a null
|
| 293 |
pointer.
|
| 294 |
|
| 295 |
+
*Remarks:* This function is replaceable [[term.replaceable.function]].
|
| 296 |
+
|
| 297 |
``` cpp
|
| 298 |
void operator delete[](void* ptr) noexcept;
|
| 299 |
void operator delete[](void* ptr, std::size_t size) noexcept;
|
| 300 |
void operator delete[](void* ptr, std::align_val_t alignment) noexcept;
|
| 301 |
void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;
|
|
|
|
| 316 |
|
| 317 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 318 |
called by the array form of a *delete-expression* to render the value of
|
| 319 |
`ptr` invalid.
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
*Required behavior:* A call to an `operator delete[]` with a `size`
|
| 322 |
parameter may be changed to a call to the corresponding
|
| 323 |
`operator delete[]` without a `size` parameter, without affecting memory
|
| 324 |
allocation.
|
| 325 |
|
| 326 |
+
[*Note 1*: A conforming implementation is for
|
| 327 |
`operator delete[](void* ptr, std::size_t size)` to simply call
|
| 328 |
`operator delete[](ptr)`. — *end note*]
|
| 329 |
|
| 330 |
*Default behavior:* The functions that have a `size` parameter forward
|
| 331 |
their other parameters to the corresponding function without a `size`
|
| 332 |
parameter. The functions that do not have a `size` parameter forward
|
| 333 |
their parameters to the corresponding `operator delete` (single-object)
|
| 334 |
function.
|
| 335 |
|
| 336 |
+
*Remarks:* This function is replaceable [[term.replaceable.function]].
|
| 337 |
+
If a replacement function without a `size` parameter is defined by the
|
| 338 |
+
program, the program should also define the corresponding function with
|
| 339 |
+
a `size` parameter. If a replacement function with a `size` parameter is
|
| 340 |
+
defined by the program, the program shall also define the corresponding
|
| 341 |
+
version without the `size` parameter.
|
| 342 |
+
|
| 343 |
+
[*Note 2*: The default behavior above might change in the future, which
|
| 344 |
+
will require replacing both deallocation functions when replacing the
|
| 345 |
+
allocation function. — *end note*]
|
| 346 |
+
|
| 347 |
``` cpp
|
| 348 |
void operator delete[](void* ptr, const std::nothrow_t&) noexcept;
|
| 349 |
void operator delete[](void* ptr, std::align_val_t alignment, const std::nothrow_t&) noexcept;
|
| 350 |
```
|
| 351 |
|
|
|
|
| 363 |
*Effects:* The deallocation functions [[basic.stc.dynamic.deallocation]]
|
| 364 |
called by the implementation to render the value of `ptr` invalid when
|
| 365 |
the constructor invoked from a nothrow placement version of the array
|
| 366 |
*new-expression* throws an exception.
|
| 367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
*Default behavior:* Calls `operator delete[](ptr)`, or
|
| 369 |
`operator delete[](ptr, alignment)`, respectively.
|
| 370 |
|
| 371 |
+
*Remarks:* This function is replaceable [[term.replaceable.function]].
|
| 372 |
+
|
| 373 |
#### Non-allocating forms <a id="new.delete.placement">[[new.delete.placement]]</a>
|
| 374 |
|
| 375 |
These functions are reserved; a C++ program may not define functions
|
| 376 |
that displace the versions in the C++ standard library [[constraints]].
|
| 377 |
The provisions of [[basic.stc.dynamic]] do not apply to these reserved
|
| 378 |
placement forms of `operator new` and `operator delete`.
|
| 379 |
|
| 380 |
``` cpp
|
| 381 |
+
constexpr void* operator new(std::size_t size, void* ptr) noexcept;
|
| 382 |
```
|
| 383 |
|
| 384 |
*Returns:* `ptr`.
|
| 385 |
|
| 386 |
*Remarks:* Intentionally performs no other action.
|
|
|
|
| 395 |
```
|
| 396 |
|
| 397 |
— *end example*]
|
| 398 |
|
| 399 |
``` cpp
|
| 400 |
+
constexpr void* operator new[](std::size_t size, void* ptr) noexcept;
|
| 401 |
```
|
| 402 |
|
| 403 |
*Returns:* `ptr`.
|
| 404 |
|
| 405 |
*Remarks:* Intentionally performs no other action.
|
|
|
|
| 444 |
``` cpp
|
| 445 |
namespace std {
|
| 446 |
class bad_alloc : public exception {
|
| 447 |
public:
|
| 448 |
// see [exception] for the specification of the special member functions
|
| 449 |
+
constexpr const char* what() const noexcept override;
|
| 450 |
};
|
| 451 |
}
|
| 452 |
```
|
| 453 |
|
| 454 |
The class `bad_alloc` defines the type of objects thrown as exceptions
|
| 455 |
by the implementation to report a failure to allocate storage.
|
| 456 |
|
| 457 |
``` cpp
|
| 458 |
+
constexpr const char* what() const noexcept override;
|
| 459 |
```
|
| 460 |
|
| 461 |
*Returns:* An *implementation-defined* NTBS.
|
| 462 |
|
| 463 |
#### Class `bad_array_new_length` <a id="new.badlength">[[new.badlength]]</a>
|
|
|
|
| 465 |
``` cpp
|
| 466 |
namespace std {
|
| 467 |
class bad_array_new_length : public bad_alloc {
|
| 468 |
public:
|
| 469 |
// see [exception] for the specification of the special member functions
|
| 470 |
+
constexpr const char* what() const noexcept override;
|
| 471 |
};
|
| 472 |
}
|
| 473 |
```
|
| 474 |
|
| 475 |
The class `bad_array_new_length` defines the type of objects thrown as
|
| 476 |
exceptions by the implementation to report an attempt to allocate an
|
| 477 |
array of size less than zero or greater than an *implementation-defined*
|
| 478 |
limit [[expr.new]].
|
| 479 |
|
| 480 |
``` cpp
|
| 481 |
+
constexpr const char* what() const noexcept override;
|
| 482 |
```
|
| 483 |
|
| 484 |
*Returns:* An *implementation-defined* NTBS.
|
| 485 |
|
| 486 |
#### Type `new_handler` <a id="new.handler">[[new.handler]]</a>
|
|
|
|
| 524 |
[*Note 1*: This can be a null pointer value. — *end note*]
|
| 525 |
|
| 526 |
### Pointer optimization barrier <a id="ptr.launder">[[ptr.launder]]</a>
|
| 527 |
|
| 528 |
``` cpp
|
| 529 |
+
template<class T> constexpr T* launder(T* p) noexcept;
|
| 530 |
```
|
| 531 |
|
| 532 |
*Mandates:* `!is_function_v<T> && !is_void_v<T>` is `true`.
|
| 533 |
|
| 534 |
*Preconditions:* `p` represents the address *A* of a byte in memory. An
|