- tmp/tmpcpnzjt29/{from.md → to.md} +127 -107
tmp/tmpcpnzjt29/{from.md → to.md}
RENAMED
|
@@ -1,42 +1,51 @@
|
|
| 1 |
## Storage duration <a id="basic.stc">[[basic.stc]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
-
potential lifetime of the storage containing the object. The
|
| 5 |
-
duration is determined by the construct used to create the
|
| 6 |
-
one of the following:
|
| 7 |
|
| 8 |
- static storage duration
|
| 9 |
- thread storage duration
|
| 10 |
- automatic storage duration
|
| 11 |
- dynamic storage duration
|
| 12 |
|
| 13 |
Static, thread, and automatic storage durations are associated with
|
| 14 |
objects introduced by declarations ([[basic.def]]) and implicitly
|
| 15 |
created by the implementation ([[class.temporary]]). The dynamic
|
| 16 |
-
storage duration is associated with objects created
|
| 17 |
-
|
| 18 |
|
| 19 |
-
The storage duration categories apply to references as well.
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
### Static storage duration <a id="basic.stc.static">[[basic.stc.static]]</a>
|
| 23 |
|
| 24 |
All variables which do not have dynamic storage duration, do not have
|
| 25 |
thread storage duration, and are not local have *static storage
|
| 26 |
duration*. The storage for these entities shall last for the duration of
|
| 27 |
-
the program ([[basic.start.
|
| 28 |
|
| 29 |
If a variable with static storage duration has initialization or a
|
| 30 |
destructor with side effects, it shall not be eliminated even if it
|
| 31 |
appears to be unused, except that a class object or its copy/move may be
|
| 32 |
eliminated as specified in [[class.copy]].
|
| 33 |
|
| 34 |
The keyword `static` can be used to declare a local variable with static
|
| 35 |
-
storage duration.
|
| 36 |
-
|
| 37 |
-
local `static`
|
|
|
|
|
|
|
| 38 |
|
| 39 |
The keyword `static` applied to a class data member in a class
|
| 40 |
definition gives the data member static storage duration.
|
| 41 |
|
| 42 |
### Thread storage duration <a id="basic.stc.thread">[[basic.stc.thread]]</a>
|
|
@@ -51,23 +60,22 @@ A variable with thread storage duration shall be initialized before its
|
|
| 51 |
first odr-use ([[basic.def.odr]]) and, if constructed, shall be
|
| 52 |
destroyed on thread exit.
|
| 53 |
|
| 54 |
### Automatic storage duration <a id="basic.stc.auto">[[basic.stc.auto]]</a>
|
| 55 |
|
| 56 |
-
Block-scope variables explicitly declared `
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
created exits.
|
| 60 |
|
| 61 |
-
These variables are initialized and destroyed as described
|
| 62 |
-
[[stmt.dcl]].
|
| 63 |
|
| 64 |
If a variable with automatic storage duration has initialization or a
|
| 65 |
-
destructor with side effects,
|
| 66 |
-
of its block
|
| 67 |
-
appears to be unused, except that a class object or its copy/move may
|
| 68 |
-
eliminated as specified in [[class.copy]].
|
| 69 |
|
| 70 |
### Dynamic storage duration <a id="basic.stc.dynamic">[[basic.stc.dynamic]]</a>
|
| 71 |
|
| 72 |
Objects can be created dynamically during program execution (
|
| 73 |
[[intro.execution]]), using *new-expression*s ([[expr.new]]), and
|
|
@@ -75,10 +83,14 @@ destroyed using *delete-expression*s ([[expr.delete]]). A
|
|
| 75 |
C++implementation provides access to, and management of, dynamic storage
|
| 76 |
via the global *allocation functions* `operator new` and `operator
|
| 77 |
new[]` and the global *deallocation functions* `operator
|
| 78 |
delete` and `operator delete[]`.
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
The library provides default definitions for the global allocation and
|
| 81 |
deallocation functions. Some global allocation and deallocation
|
| 82 |
functions are replaceable ([[new.delete]]). A C++program shall provide
|
| 83 |
at most one definition of a replaceable allocation or deallocation
|
| 84 |
function. Any such function definition replaces the default version
|
|
@@ -87,27 +99,41 @@ allocation and deallocation functions ([[support.dynamic]]) are
|
|
| 87 |
implicitly declared in global scope in each translation unit of a
|
| 88 |
program.
|
| 89 |
|
| 90 |
``` cpp
|
| 91 |
void* operator new(std::size_t);
|
| 92 |
-
void* operator new
|
|
|
|
| 93 |
void operator delete(void*) noexcept;
|
| 94 |
-
void operator delete[](void*) noexcept;
|
| 95 |
void operator delete(void*, std::size_t) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
void operator delete[](void*, std::size_t) noexcept;
|
|
|
|
|
|
|
| 97 |
```
|
| 98 |
|
| 99 |
These implicit declarations introduce only the function names `operator`
|
| 100 |
`new`, `operator` `new[]`, `operator` `delete`, and `operator`
|
| 101 |
-
`delete[]`.
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
Any allocation and/or deallocation functions defined in a C++program,
|
| 111 |
including the default versions in the library, shall conform to the
|
| 112 |
semantics specified in [[basic.stc.dynamic.allocation]] and
|
| 113 |
[[basic.stc.dynamic.deallocation]].
|
|
@@ -132,102 +158,91 @@ storage. If it is successful, it shall return the address of the start
|
|
| 132 |
of a block of storage whose length in bytes shall be at least as large
|
| 133 |
as the requested size. There are no constraints on the contents of the
|
| 134 |
allocated storage on return from the allocation function. The order,
|
| 135 |
contiguity, and initial value of storage allocated by successive calls
|
| 136 |
to an allocation function are unspecified. The pointer returned shall be
|
| 137 |
-
suitably aligned so that it can be converted to a pointer
|
| 138 |
-
complete object type
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
An allocation function that fails to allocate storage can invoke the
|
| 150 |
-
currently installed new-handler function ([[new.handler]]), if any.
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
A global allocation function is only called as the result of a new
|
| 161 |
expression ([[expr.new]]), or called directly using the function call
|
| 162 |
syntax ([[expr.call]]), or called indirectly through calls to the
|
| 163 |
-
functions in the C++standard library.
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
[[
|
|
|
|
|
|
|
| 169 |
|
| 170 |
#### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
|
| 171 |
|
| 172 |
Deallocation functions shall be class member functions or global
|
| 173 |
functions; a program is ill-formed if deallocation functions are
|
| 174 |
declared in a namespace scope other than global scope or declared static
|
| 175 |
in global scope.
|
| 176 |
|
| 177 |
Each deallocation function shall return `void` and its first parameter
|
| 178 |
-
shall be `void*`. A deallocation function
|
| 179 |
-
parameter.
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
parameters, the
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
deallocation function named `operator` `delete[]` with exactly one
|
| 194 |
-
parameter, then that function is a usual (non-placement) deallocation
|
| 195 |
-
function. If class `T` does not declare such an `operator` `delete[]`
|
| 196 |
-
but does declare a member deallocation function named `operator`
|
| 197 |
-
`delete[]` with exactly two parameters, the second of which has type
|
| 198 |
-
`std::size_t`, then this function is a usual deallocation function. A
|
| 199 |
-
deallocation function can be an instance of a function template. Neither
|
| 200 |
-
the first parameter nor the return type shall depend on a template
|
| 201 |
-
parameter. That is, a deallocation function template shall have a first
|
| 202 |
parameter of type `void*` and a return type of `void` (as specified
|
| 203 |
-
above).
|
|
|
|
|
|
|
| 204 |
parameters. A template instance is never a usual deallocation function,
|
| 205 |
regardless of its signature.
|
| 206 |
|
| 207 |
If a deallocation function terminates by throwing an exception, the
|
| 208 |
behavior is undefined. The value of the first argument supplied to a
|
| 209 |
deallocation function may be a null pointer value; if so, and if the
|
| 210 |
deallocation function is one supplied in the standard library, the call
|
| 211 |
-
has no effect.
|
| 212 |
-
supplied to `operator` `delete(void*)` in the standard library is not
|
| 213 |
-
one of the values returned by a previous invocation of either `operator`
|
| 214 |
-
`new(std::size_t)` or `operator` `new(std::size_t,` `const`
|
| 215 |
-
`std::nothrow_t&)` in the standard library, and the behavior is
|
| 216 |
-
undefined if the value supplied to `operator` `delete[](void*)` in the
|
| 217 |
-
standard library is not one of the values returned by a previous
|
| 218 |
-
invocation of either `operator` `new[](std::size_t)` or `operator`
|
| 219 |
-
`new[](std::size_t,` `const` `std::nothrow_t&)` in the standard library.
|
| 220 |
|
| 221 |
If the argument given to a deallocation function in the standard library
|
| 222 |
is a pointer that is not the null pointer value ([[conv.ptr]]), the
|
| 223 |
deallocation function shall deallocate the storage referenced by the
|
| 224 |
-
pointer,
|
| 225 |
-
deallocated storage. Indirection through an invalid pointer value and
|
| 226 |
-
passing an invalid pointer value to a deallocation function have
|
| 227 |
-
undefined behavior. Any other use of an invalid pointer value has
|
| 228 |
-
implementation-defined behavior.[^14]
|
| 229 |
|
| 230 |
#### Safely-derived pointers <a id="basic.stc.dynamic.safety">[[basic.stc.dynamic.safety]]</a>
|
| 231 |
|
| 232 |
A *traceable pointer object* is
|
| 233 |
|
|
@@ -240,11 +255,12 @@ A *traceable pointer object* is
|
|
| 240 |
|
| 241 |
A pointer value is a *safely-derived pointer* to a dynamic object only
|
| 242 |
if it has an object pointer type and it is one of the following:
|
| 243 |
|
| 244 |
- the value returned by a call to the C++standard library implementation
|
| 245 |
-
of `::operator new(std::size_t)`
|
|
|
|
| 246 |
- the result of taking the address of an object (or one of its
|
| 247 |
subobjects) designated by an lvalue resulting from indirection through
|
| 248 |
a safely-derived pointer value;
|
| 249 |
- the result of well-defined pointer arithmetic ([[expr.add]]) using a
|
| 250 |
safely-derived pointer value;
|
|
@@ -255,13 +271,13 @@ if it has an object pointer type and it is one of the following:
|
|
| 255 |
safely-derived pointer value;
|
| 256 |
- the value of an object whose value was copied from a traceable pointer
|
| 257 |
object, where at the time of the copy the source object contained a
|
| 258 |
copy of a safely-derived pointer value.
|
| 259 |
|
| 260 |
-
An integer value is an
|
| 261 |
-
|
| 262 |
-
|
| 263 |
|
| 264 |
- the result of a `reinterpret_cast` of a safely-derived pointer value;
|
| 265 |
- the result of a valid conversion of an integer representation of a
|
| 266 |
safely-derived pointer value;
|
| 267 |
- the value of an object whose value was copied from a traceable pointer
|
|
@@ -278,17 +294,21 @@ validity of a pointer value does not depend on whether it is a
|
|
| 278 |
safely-derived pointer value. Alternatively, an implementation may have
|
| 279 |
*strict pointer safety*, in which case a pointer value referring to an
|
| 280 |
object with dynamic storage duration that is not a safely-derived
|
| 281 |
pointer value is an invalid pointer value unless the referenced complete
|
| 282 |
object has previously been declared reachable (
|
| 283 |
-
[[util.dynamic.safety]]).
|
| 284 |
-
|
|
|
|
|
|
|
| 285 |
[[basic.stc.dynamic.deallocation]]. This is true even if the
|
| 286 |
unsafely-derived pointer value might compare equal to some
|
| 287 |
-
safely-derived pointer value.
|
| 288 |
-
|
|
|
|
|
|
|
| 289 |
|
| 290 |
### Duration of subobjects <a id="basic.stc.inherit">[[basic.stc.inherit]]</a>
|
| 291 |
|
| 292 |
-
The storage duration of
|
| 293 |
-
|
| 294 |
|
|
|
|
| 1 |
## Storage duration <a id="basic.stc">[[basic.stc]]</a>
|
| 2 |
|
| 3 |
+
The *storage duration* is the property of an object that defines the
|
| 4 |
+
minimum potential lifetime of the storage containing the object. The
|
| 5 |
+
storage duration is determined by the construct used to create the
|
| 6 |
+
object and is one of the following:
|
| 7 |
|
| 8 |
- static storage duration
|
| 9 |
- thread storage duration
|
| 10 |
- automatic storage duration
|
| 11 |
- dynamic storage duration
|
| 12 |
|
| 13 |
Static, thread, and automatic storage durations are associated with
|
| 14 |
objects introduced by declarations ([[basic.def]]) and implicitly
|
| 15 |
created by the implementation ([[class.temporary]]). The dynamic
|
| 16 |
+
storage duration is associated with objects created by a
|
| 17 |
+
*new-expression* ([[expr.new]]).
|
| 18 |
|
| 19 |
+
The storage duration categories apply to references as well.
|
| 20 |
+
|
| 21 |
+
When the end of the duration of a region of storage is reached, the
|
| 22 |
+
values of all pointers representing the address of any part of that
|
| 23 |
+
region of storage become invalid pointer values ([[basic.compound]]).
|
| 24 |
+
Indirection through an invalid pointer value and passing an invalid
|
| 25 |
+
pointer value to a deallocation function have undefined behavior. Any
|
| 26 |
+
other use of an invalid pointer value has *implementation-defined*
|
| 27 |
+
behavior.[^12]
|
| 28 |
|
| 29 |
### Static storage duration <a id="basic.stc.static">[[basic.stc.static]]</a>
|
| 30 |
|
| 31 |
All variables which do not have dynamic storage duration, do not have
|
| 32 |
thread storage duration, and are not local have *static storage
|
| 33 |
duration*. The storage for these entities shall last for the duration of
|
| 34 |
+
the program ([[basic.start.static]], [[basic.start.term]]).
|
| 35 |
|
| 36 |
If a variable with static storage duration has initialization or a
|
| 37 |
destructor with side effects, it shall not be eliminated even if it
|
| 38 |
appears to be unused, except that a class object or its copy/move may be
|
| 39 |
eliminated as specified in [[class.copy]].
|
| 40 |
|
| 41 |
The keyword `static` can be used to declare a local variable with static
|
| 42 |
+
storage duration.
|
| 43 |
+
|
| 44 |
+
[*Note 1*: [[stmt.dcl]] describes the initialization of local `static`
|
| 45 |
+
variables; [[basic.start.term]] describes the destruction of local
|
| 46 |
+
`static` variables. — *end note*]
|
| 47 |
|
| 48 |
The keyword `static` applied to a class data member in a class
|
| 49 |
definition gives the data member static storage duration.
|
| 50 |
|
| 51 |
### Thread storage duration <a id="basic.stc.thread">[[basic.stc.thread]]</a>
|
|
|
|
| 60 |
first odr-use ([[basic.def.odr]]) and, if constructed, shall be
|
| 61 |
destroyed on thread exit.
|
| 62 |
|
| 63 |
### Automatic storage duration <a id="basic.stc.auto">[[basic.stc.auto]]</a>
|
| 64 |
|
| 65 |
+
Block-scope variables not explicitly declared `static`, `thread_local`,
|
| 66 |
+
or `extern` have *automatic storage duration*. The storage for these
|
| 67 |
+
entities lasts until the block in which they are created exits.
|
|
|
|
| 68 |
|
| 69 |
+
[*Note 1*: These variables are initialized and destroyed as described
|
| 70 |
+
in [[stmt.dcl]]. — *end note*]
|
| 71 |
|
| 72 |
If a variable with automatic storage duration has initialization or a
|
| 73 |
+
destructor with side effects, an implementation shall not destroy it
|
| 74 |
+
before the end of its block nor eliminate it as an optimization, even if
|
| 75 |
+
it appears to be unused, except that a class object or its copy/move may
|
| 76 |
+
be eliminated as specified in [[class.copy]].
|
| 77 |
|
| 78 |
### Dynamic storage duration <a id="basic.stc.dynamic">[[basic.stc.dynamic]]</a>
|
| 79 |
|
| 80 |
Objects can be created dynamically during program execution (
|
| 81 |
[[intro.execution]]), using *new-expression*s ([[expr.new]]), and
|
|
|
|
| 83 |
C++implementation provides access to, and management of, dynamic storage
|
| 84 |
via the global *allocation functions* `operator new` and `operator
|
| 85 |
new[]` and the global *deallocation functions* `operator
|
| 86 |
delete` and `operator delete[]`.
|
| 87 |
|
| 88 |
+
[*Note 1*: The non-allocating forms described in
|
| 89 |
+
[[new.delete.placement]] do not perform allocation or
|
| 90 |
+
deallocation. — *end note*]
|
| 91 |
+
|
| 92 |
The library provides default definitions for the global allocation and
|
| 93 |
deallocation functions. Some global allocation and deallocation
|
| 94 |
functions are replaceable ([[new.delete]]). A C++program shall provide
|
| 95 |
at most one definition of a replaceable allocation or deallocation
|
| 96 |
function. Any such function definition replaces the default version
|
|
|
|
| 99 |
implicitly declared in global scope in each translation unit of a
|
| 100 |
program.
|
| 101 |
|
| 102 |
``` cpp
|
| 103 |
void* operator new(std::size_t);
|
| 104 |
+
void* operator new(std::size_t, std::align_val_t);
|
| 105 |
+
|
| 106 |
void operator delete(void*) noexcept;
|
|
|
|
| 107 |
void operator delete(void*, std::size_t) noexcept;
|
| 108 |
+
void operator delete(void*, std::align_val_t) noexcept;
|
| 109 |
+
void operator delete(void*, std::size_t, std::align_val_t) noexcept;
|
| 110 |
+
|
| 111 |
+
void* operator new[](std::size_t);
|
| 112 |
+
void* operator new[](std::size_t, std::align_val_t);
|
| 113 |
+
|
| 114 |
+
void operator delete[](void*) noexcept;
|
| 115 |
void operator delete[](void*, std::size_t) noexcept;
|
| 116 |
+
void operator delete[](void*, std::align_val_t) noexcept;
|
| 117 |
+
void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
|
| 118 |
```
|
| 119 |
|
| 120 |
These implicit declarations introduce only the function names `operator`
|
| 121 |
`new`, `operator` `new[]`, `operator` `delete`, and `operator`
|
| 122 |
+
`delete[]`.
|
| 123 |
+
|
| 124 |
+
[*Note 2*: The implicit declarations do not introduce the names `std`,
|
| 125 |
+
`std::size_t`, `std::align_val_t`, or any other names that the library
|
| 126 |
+
uses to declare these names. Thus, a *new-expression*,
|
| 127 |
+
*delete-expression* or function call that refers to one of these
|
| 128 |
+
functions without including the header `<new>` is well-formed. However,
|
| 129 |
+
referring to `std` or `std::size_t` or `std::align_val_t` is ill-formed
|
| 130 |
+
unless the name has been declared by including the appropriate
|
| 131 |
+
header. — *end note*]
|
| 132 |
+
|
| 133 |
+
Allocation and/or deallocation functions may also be declared and
|
| 134 |
+
defined for any class ([[class.free]]).
|
| 135 |
|
| 136 |
Any allocation and/or deallocation functions defined in a C++program,
|
| 137 |
including the default versions in the library, shall conform to the
|
| 138 |
semantics specified in [[basic.stc.dynamic.allocation]] and
|
| 139 |
[[basic.stc.dynamic.deallocation]].
|
|
|
|
| 158 |
of a block of storage whose length in bytes shall be at least as large
|
| 159 |
as the requested size. There are no constraints on the contents of the
|
| 160 |
allocated storage on return from the allocation function. The order,
|
| 161 |
contiguity, and initial value of storage allocated by successive calls
|
| 162 |
to an allocation function are unspecified. The pointer returned shall be
|
| 163 |
+
suitably aligned so that it can be converted to a pointer to any
|
| 164 |
+
suitable complete object type ([[new.delete.single]]) and then used to
|
| 165 |
+
access the object or array in the storage allocated (until the storage
|
| 166 |
+
is explicitly deallocated by a call to a corresponding deallocation
|
| 167 |
+
function). Even if the size of the space requested is zero, the request
|
| 168 |
+
can fail. If the request succeeds, the value returned shall be a
|
| 169 |
+
non-null pointer value ([[conv.ptr]]) `p0` different from any
|
| 170 |
+
previously returned value `p1`, unless that value `p1` was subsequently
|
| 171 |
+
passed to an `operator` `delete`. Furthermore, for the library
|
| 172 |
+
allocation functions in [[new.delete.single]] and
|
| 173 |
+
[[new.delete.array]], `p0` shall represent the address of a block of
|
| 174 |
+
storage disjoint from the storage for any other object accessible to the
|
| 175 |
+
caller. The effect of indirecting through a pointer returned as a
|
| 176 |
+
request for zero size is undefined.[^13]
|
| 177 |
|
| 178 |
An allocation function that fails to allocate storage can invoke the
|
| 179 |
+
currently installed new-handler function ([[new.handler]]), if any.
|
| 180 |
+
|
| 181 |
+
[*Note 1*: A program-supplied allocation function can obtain the
|
| 182 |
+
address of the currently installed `new_handler` using the
|
| 183 |
+
`std::get_new_handler` function ([[set.new.handler]]). — *end note*]
|
| 184 |
+
|
| 185 |
+
If an allocation function that has a non-throwing exception
|
| 186 |
+
specification ([[except.spec]]) fails to allocate storage, it shall
|
| 187 |
+
return a null pointer. Any other allocation function that fails to
|
| 188 |
+
allocate storage shall indicate failure only by throwing an exception (
|
| 189 |
+
[[except.throw]]) of a type that would match a handler (
|
| 190 |
+
[[except.handle]]) of type `std::bad_alloc` ([[bad.alloc]]).
|
| 191 |
|
| 192 |
A global allocation function is only called as the result of a new
|
| 193 |
expression ([[expr.new]]), or called directly using the function call
|
| 194 |
syntax ([[expr.call]]), or called indirectly through calls to the
|
| 195 |
+
functions in the C++standard library.
|
| 196 |
+
|
| 197 |
+
[*Note 2*: In particular, a global allocation function is not called to
|
| 198 |
+
allocate storage for objects with static storage duration (
|
| 199 |
+
[[basic.stc.static]]), for objects or references with thread storage
|
| 200 |
+
duration ([[basic.stc.thread]]), for objects of type `std::type_info` (
|
| 201 |
+
[[expr.typeid]]), or for an exception object (
|
| 202 |
+
[[except.throw]]). — *end note*]
|
| 203 |
|
| 204 |
#### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
|
| 205 |
|
| 206 |
Deallocation functions shall be class member functions or global
|
| 207 |
functions; a program is ill-formed if deallocation functions are
|
| 208 |
declared in a namespace scope other than global scope or declared static
|
| 209 |
in global scope.
|
| 210 |
|
| 211 |
Each deallocation function shall return `void` and its first parameter
|
| 212 |
+
shall be `void*`. A deallocation function may have more than one
|
| 213 |
+
parameter. A *usual deallocation function* is a deallocation function
|
| 214 |
+
that has:
|
| 215 |
+
|
| 216 |
+
- exactly one parameter; or
|
| 217 |
+
- exactly two parameters, the type of the second being either
|
| 218 |
+
`std::align_val_t` or `std::size_t` [^14]; or
|
| 219 |
+
- exactly three parameters, the type of the second being `std::size_t`
|
| 220 |
+
and the type of the third being `std::align_val_t`.
|
| 221 |
+
|
| 222 |
+
A deallocation function may be an instance of a function template.
|
| 223 |
+
Neither the first parameter nor the return type shall depend on a
|
| 224 |
+
template parameter.
|
| 225 |
+
|
| 226 |
+
[*Note 1*: That is, a deallocation function template shall have a first
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
parameter of type `void*` and a return type of `void` (as specified
|
| 228 |
+
above). — *end note*]
|
| 229 |
+
|
| 230 |
+
A deallocation function template shall have two or more function
|
| 231 |
parameters. A template instance is never a usual deallocation function,
|
| 232 |
regardless of its signature.
|
| 233 |
|
| 234 |
If a deallocation function terminates by throwing an exception, the
|
| 235 |
behavior is undefined. The value of the first argument supplied to a
|
| 236 |
deallocation function may be a null pointer value; if so, and if the
|
| 237 |
deallocation function is one supplied in the standard library, the call
|
| 238 |
+
has no effect.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
If the argument given to a deallocation function in the standard library
|
| 241 |
is a pointer that is not the null pointer value ([[conv.ptr]]), the
|
| 242 |
deallocation function shall deallocate the storage referenced by the
|
| 243 |
+
pointer, ending the duration of the region of storage.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
#### Safely-derived pointers <a id="basic.stc.dynamic.safety">[[basic.stc.dynamic.safety]]</a>
|
| 246 |
|
| 247 |
A *traceable pointer object* is
|
| 248 |
|
|
|
|
| 255 |
|
| 256 |
A pointer value is a *safely-derived pointer* to a dynamic object only
|
| 257 |
if it has an object pointer type and it is one of the following:
|
| 258 |
|
| 259 |
- the value returned by a call to the C++standard library implementation
|
| 260 |
+
of `::operator new(std::{}size_t)` or
|
| 261 |
+
`::operator new(std::size_t, std::align_val_t)` ;[^15]
|
| 262 |
- the result of taking the address of an object (or one of its
|
| 263 |
subobjects) designated by an lvalue resulting from indirection through
|
| 264 |
a safely-derived pointer value;
|
| 265 |
- the result of well-defined pointer arithmetic ([[expr.add]]) using a
|
| 266 |
safely-derived pointer value;
|
|
|
|
| 271 |
safely-derived pointer value;
|
| 272 |
- the value of an object whose value was copied from a traceable pointer
|
| 273 |
object, where at the time of the copy the source object contained a
|
| 274 |
copy of a safely-derived pointer value.
|
| 275 |
|
| 276 |
+
An integer value is an *integer representation of a safely-derived
|
| 277 |
+
pointer* only if its type is at least as large as `std::intptr_t` and it
|
| 278 |
+
is one of the following:
|
| 279 |
|
| 280 |
- the result of a `reinterpret_cast` of a safely-derived pointer value;
|
| 281 |
- the result of a valid conversion of an integer representation of a
|
| 282 |
safely-derived pointer value;
|
| 283 |
- the value of an object whose value was copied from a traceable pointer
|
|
|
|
| 294 |
safely-derived pointer value. Alternatively, an implementation may have
|
| 295 |
*strict pointer safety*, in which case a pointer value referring to an
|
| 296 |
object with dynamic storage duration that is not a safely-derived
|
| 297 |
pointer value is an invalid pointer value unless the referenced complete
|
| 298 |
object has previously been declared reachable (
|
| 299 |
+
[[util.dynamic.safety]]).
|
| 300 |
+
|
| 301 |
+
[*Note 1*: The effect of using an invalid pointer value (including
|
| 302 |
+
passing it to a deallocation function) is undefined, see
|
| 303 |
[[basic.stc.dynamic.deallocation]]. This is true even if the
|
| 304 |
unsafely-derived pointer value might compare equal to some
|
| 305 |
+
safely-derived pointer value. — *end note*]
|
| 306 |
+
|
| 307 |
+
It is *implementation-defined* whether an implementation has relaxed or
|
| 308 |
+
strict pointer safety.
|
| 309 |
|
| 310 |
### Duration of subobjects <a id="basic.stc.inherit">[[basic.stc.inherit]]</a>
|
| 311 |
|
| 312 |
+
The storage duration of subobjects and reference members is that of
|
| 313 |
+
their complete object ([[intro.object]]).
|
| 314 |
|