From Jason Turner

[basic.stc.dynamic]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpnb8ed668/{from.md → to.md} +36 -99
tmp/tmpnb8ed668/{from.md → to.md} RENAMED
@@ -1,27 +1,30 @@
1
  #### Dynamic storage duration <a id="basic.stc.dynamic">[[basic.stc.dynamic]]</a>
2
 
 
 
3
  Objects can be created dynamically during program execution
4
  [[intro.execution]], using *new-expression*s [[expr.new]], and destroyed
5
  using *delete-expression*s [[expr.delete]]. A C++ implementation
6
  provides access to, and management of, dynamic storage via the global
7
- *allocation functions* `operator new` and `operator
8
- new[]` and the global *deallocation functions* `operator
9
- delete` and `operator delete[]`.
10
 
11
  [*Note 1*: The non-allocating forms described in
12
  [[new.delete.placement]] do not perform allocation or
13
  deallocation. — *end note*]
14
 
15
  The library provides default definitions for the global allocation and
16
  deallocation functions. Some global allocation and deallocation
17
- functions are replaceable [[new.delete]]. A C++ program shall provide at
18
- most one definition of a replaceable allocation or deallocation
19
- function. Any such function definition replaces the default version
20
- provided in the library [[replacement.functions]]. The following
21
- allocation and deallocation functions [[support.dynamic]] are implicitly
22
- declared in global scope in each translation unit of a program.
 
23
 
24
  ``` cpp
25
  [[nodiscard]] void* operator new(std::size_t);
26
  [[nodiscard]] void* operator new(std::size_t, std::align_val_t);
27
 
@@ -37,22 +40,24 @@ void operator delete[](void*) noexcept;
37
  void operator delete[](void*, std::size_t) noexcept;
38
  void operator delete[](void*, std::align_val_t) noexcept;
39
  void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
40
  ```
41
 
42
- These implicit declarations introduce only the function names `operator`
43
- `new`, `operator` `new[]`, `operator` `delete`, and `operator`
44
- `delete[]`.
45
 
46
  [*Note 2*: The implicit declarations do not introduce the names `std`,
47
  `std::size_t`, `std::align_val_t`, or any other names that the library
48
  uses to declare these names. Thus, a *new-expression*,
49
  *delete-expression*, or function call that refers to one of these
50
- functions without importing or including the header `<new>` is
51
- well-formed. However, referring to `std` or `std::size_t` or
52
- `std::align_val_t` is ill-formed unless the name has been declared by
53
- importing or including the appropriate header. — *end note*]
 
 
54
 
55
  Allocation and/or deallocation functions may also be declared and
56
  defined for any class [[class.free]].
57
 
58
  If the behavior of an allocation or deallocation function does not
@@ -60,22 +65,21 @@ satisfy the semantic constraints specified in 
60
  [[basic.stc.dynamic.allocation]] and 
61
  [[basic.stc.dynamic.deallocation]], the behavior is undefined.
62
 
63
  ##### Allocation functions <a id="basic.stc.dynamic.allocation">[[basic.stc.dynamic.allocation]]</a>
64
 
65
- An allocation function shall be a class member function or a global
66
- function; a program is ill-formed if an allocation function is declared
67
- in a namespace scope other than global scope or declared static in
68
- global scope. The return type shall be `void*`. The first parameter
69
- shall have type `std::size_t` [[support.types]]. The first parameter
70
- shall not have an associated default argument [[dcl.fct.default]]. The
71
- value of the first parameter is interpreted as the requested size of the
72
- allocation. An allocation function can be a function template. Such a
73
- template shall declare its return type and first parameter as specified
74
- above (that is, template parameter types shall not be used in the return
75
- type and first parameter type). Template allocation functions shall have
76
- two or more parameters.
77
 
78
  An allocation function attempts to allocate the requested amount of
79
  storage. If it is successful, it returns the address of the start of a
80
  block of storage whose length in bytes is at least as large as the
81
  requested size. The order, contiguity, and initial value of storage
@@ -87,11 +91,11 @@ from any previously returned value `p1`, unless that value `p1` was
87
  subsequently passed to a replaceable deallocation function. Furthermore,
88
  for the library allocation functions in  [[new.delete.single]] and 
89
  [[new.delete.array]], `p0` represents the address of a block of storage
90
  disjoint from the storage for any other object accessible to the caller.
91
  The effect of indirecting through a pointer returned from a request for
92
- zero size is undefined.[^14]
93
 
94
  For an allocation function other than a reserved placement allocation
95
  function [[new.delete.placement]], the pointer returned on a successful
96
  call shall represent the address of storage that is aligned as follows:
97
 
@@ -131,14 +135,12 @@ duration [[basic.stc.thread]], for objects of type `std::type_info`
131
  [[expr.typeid]], or for an exception object
132
  [[except.throw]]. — *end note*]
133
 
134
  ##### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
135
 
136
- Deallocation functions shall be class member functions or global
137
- functions; a program is ill-formed if deallocation functions are
138
- declared in a namespace scope other than global scope or declared static
139
- in global scope.
140
 
141
  A deallocation function is a *destroying operator delete* if it has at
142
  least two parameters and its second parameter is of type
143
  `std::destroying_delete_t`. A destroying operator delete shall be a
144
  class member function named `operator delete`.
@@ -152,11 +154,11 @@ first parameter shall be `C*`; otherwise, the type of its first
152
  parameter shall be `void*`. A deallocation function may have more than
153
  one parameter. A *usual deallocation function* is a deallocation
154
  function whose parameters after the first are
155
 
156
  - optionally, a parameter of type `std::destroying_delete_t`, then
157
- - optionally, a parameter of type `std::size_t` [^15], then
158
  - optionally, a parameter of type `std::align_val_t`.
159
 
160
  A destroying operator delete shall be a usual deallocation function. A
161
  deallocation function may be an instance of a function template. Neither
162
  the first parameter nor the return type shall depend on a template
@@ -173,70 +175,5 @@ has no effect.
173
  If the argument given to a deallocation function in the standard library
174
  is a pointer that is not the null pointer value [[basic.compound]], the
175
  deallocation function shall deallocate the storage referenced by the
176
  pointer, ending the duration of the region of storage.
177
 
178
- ##### Safely-derived pointers <a id="basic.stc.dynamic.safety">[[basic.stc.dynamic.safety]]</a>
179
-
180
- A *traceable pointer object* is
181
-
182
- - an object of an object pointer type [[basic.compound]], or
183
- - an object of an integral type that is at least as large as
184
- `std::intptr_t`, or
185
- - a sequence of elements in an array of narrow character type
186
- [[basic.fundamental]], where the size and alignment of the sequence
187
- match those of some object pointer type.
188
-
189
- A pointer value is a *safely-derived pointer* to an object with dynamic
190
- storage duration only if the pointer value has an object pointer type
191
- and is one of the following:
192
-
193
- - the value returned by a call to the C++ standard library
194
- implementation of `::operator new(std::{}size_t)` or
195
- `::operator new(std::size_t, std::align_val_t)` ;[^16]
196
- - the result of taking the address of an object (or one of its
197
- subobjects) designated by an lvalue resulting from indirection through
198
- a safely-derived pointer value;
199
- - the result of well-defined pointer arithmetic [[expr.add]] using a
200
- safely-derived pointer value;
201
- - the result of a well-defined pointer conversion ([[conv.ptr]],
202
- [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]]) of a
203
- safely-derived pointer value;
204
- - the result of a `reinterpret_cast` of a safely-derived pointer value;
205
- - the result of a `reinterpret_cast` of an integer representation of a
206
- safely-derived pointer value;
207
- - the value of an object whose value was copied from a traceable pointer
208
- object, where at the time of the copy the source object contained a
209
- copy of a safely-derived pointer value.
210
-
211
- An integer value is an *integer representation of a safely-derived
212
- pointer* only if its type is at least as large as `std::intptr_t` and it
213
- is one of the following:
214
-
215
- - the result of a `reinterpret_cast` of a safely-derived pointer value;
216
- - the result of a valid conversion of an integer representation of a
217
- safely-derived pointer value;
218
- - the value of an object whose value was copied from a traceable pointer
219
- object, where at the time of the copy the source object contained an
220
- integer representation of a safely-derived pointer value;
221
- - the result of an additive or bitwise operation, one of whose operands
222
- is an integer representation of a safely-derived pointer value `P`, if
223
- that result converted by `reinterpret_cast<void*>` would compare equal
224
- to a safely-derived pointer computable from
225
- `reinterpret_cast<void*>(P)`.
226
-
227
- An implementation may have *relaxed pointer safety*, in which case the
228
- validity of a pointer value does not depend on whether it is a
229
- safely-derived pointer value. Alternatively, an implementation may have
230
- *strict pointer safety*, in which case a pointer value referring to an
231
- object with dynamic storage duration that is not a safely-derived
232
- pointer value is an invalid pointer value unless the referenced complete
233
- object has previously been declared reachable [[util.dynamic.safety]].
234
-
235
- [*Note 6*: The effect of using an invalid pointer value (including
236
- passing it to a deallocation function) is undefined, see  [[basic.stc]].
237
- This is true even if the unsafely-derived pointer value might compare
238
- equal to some safely-derived pointer value. — *end note*]
239
-
240
- It is *implementation-defined* whether an implementation has relaxed or
241
- strict pointer safety.
242
-
 
1
  #### Dynamic storage duration <a id="basic.stc.dynamic">[[basic.stc.dynamic]]</a>
2
 
3
+ ##### General <a id="basic.stc.dynamic.general">[[basic.stc.dynamic.general]]</a>
4
+
5
  Objects can be created dynamically during program execution
6
  [[intro.execution]], using *new-expression*s [[expr.new]], and destroyed
7
  using *delete-expression*s [[expr.delete]]. A C++ implementation
8
  provides access to, and management of, dynamic storage via the global
9
+ *allocation functions* `operator new` and `operator new[]` and the
10
+ global *deallocation functions* `operator delete` and
11
+ `operator delete[]`.
12
 
13
  [*Note 1*: The non-allocating forms described in
14
  [[new.delete.placement]] do not perform allocation or
15
  deallocation. — *end note*]
16
 
17
  The library provides default definitions for the global allocation and
18
  deallocation functions. Some global allocation and deallocation
19
+ functions are replaceable [[new.delete]]; these are attached to the
20
+ global module [[module.unit]]. A C++ program shall provide at most one
21
+ definition of a replaceable allocation or deallocation function. Any
22
+ such function definition replaces the default version provided in the
23
+ library [[replacement.functions]]. The following allocation and
24
+ deallocation functions [[support.dynamic]] are implicitly declared in
25
+ global scope in each translation unit of a program.
26
 
27
  ``` cpp
28
  [[nodiscard]] void* operator new(std::size_t);
29
  [[nodiscard]] void* operator new(std::size_t, std::align_val_t);
30
 
 
40
  void operator delete[](void*, std::size_t) noexcept;
41
  void operator delete[](void*, std::align_val_t) noexcept;
42
  void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
43
  ```
44
 
45
+ These implicit declarations introduce only the function names
46
+ `operator new`, `operator new[]`, `operator delete`, and
47
+ `operator delete[]`.
48
 
49
  [*Note 2*: The implicit declarations do not introduce the names `std`,
50
  `std::size_t`, `std::align_val_t`, or any other names that the library
51
  uses to declare these names. Thus, a *new-expression*,
52
  *delete-expression*, or function call that refers to one of these
53
+ functions without importing or including the header `<new>` or importing
54
+ a C++ library module [[std.modules]] is well-formed. However, referring
55
+ to `std` or `std::size_t` or `std::align_val_t` is ill-formed unless a
56
+ standard library declaration
57
+ [[cstddef.syn]], [[new.syn]], [[std.modules]] of that name precedes
58
+ [[basic.lookup.general]] the use of that name. — *end note*]
59
 
60
  Allocation and/or deallocation functions may also be declared and
61
  defined for any class [[class.free]].
62
 
63
  If the behavior of an allocation or deallocation function does not
 
65
  [[basic.stc.dynamic.allocation]] and 
66
  [[basic.stc.dynamic.deallocation]], the behavior is undefined.
67
 
68
  ##### Allocation functions <a id="basic.stc.dynamic.allocation">[[basic.stc.dynamic.allocation]]</a>
69
 
70
+ An allocation function that is not a class member function shall belong
71
+ to the global scope and not have a name with internal linkage. The
72
+ return type shall be `void*`. The first parameter shall have type
73
+ `std::size_t` [[support.types]]. The first parameter shall not have an
74
+ associated default argument [[dcl.fct.default]]. The value of the first
75
+ parameter is interpreted as the requested size of the allocation. An
76
+ allocation function can be a function template. Such a template shall
77
+ declare its return type and first parameter as specified above (that is,
78
+ template parameter types shall not be used in the return type and first
79
+ parameter type). Allocation function templates shall have two or more
80
+ parameters.
 
81
 
82
  An allocation function attempts to allocate the requested amount of
83
  storage. If it is successful, it returns the address of the start of a
84
  block of storage whose length in bytes is at least as large as the
85
  requested size. The order, contiguity, and initial value of storage
 
91
  subsequently passed to a replaceable deallocation function. Furthermore,
92
  for the library allocation functions in  [[new.delete.single]] and 
93
  [[new.delete.array]], `p0` represents the address of a block of storage
94
  disjoint from the storage for any other object accessible to the caller.
95
  The effect of indirecting through a pointer returned from a request for
96
+ zero size is undefined.[^11]
97
 
98
  For an allocation function other than a reserved placement allocation
99
  function [[new.delete.placement]], the pointer returned on a successful
100
  call shall represent the address of storage that is aligned as follows:
101
 
 
135
  [[expr.typeid]], or for an exception object
136
  [[except.throw]]. — *end note*]
137
 
138
  ##### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
139
 
140
+ A deallocation function that is not a class member function shall belong
141
+ to the global scope and not have a name with internal linkage.
 
 
142
 
143
  A deallocation function is a *destroying operator delete* if it has at
144
  least two parameters and its second parameter is of type
145
  `std::destroying_delete_t`. A destroying operator delete shall be a
146
  class member function named `operator delete`.
 
154
  parameter shall be `void*`. A deallocation function may have more than
155
  one parameter. A *usual deallocation function* is a deallocation
156
  function whose parameters after the first are
157
 
158
  - optionally, a parameter of type `std::destroying_delete_t`, then
159
+ - optionally, a parameter of type `std::size_t`,[^12] then
160
  - optionally, a parameter of type `std::align_val_t`.
161
 
162
  A destroying operator delete shall be a usual deallocation function. A
163
  deallocation function may be an instance of a function template. Neither
164
  the first parameter nor the return type shall depend on a template
 
175
  If the argument given to a deallocation function in the standard library
176
  is a pointer that is not the null pointer value [[basic.compound]], the
177
  deallocation function shall deallocate the storage referenced by the
178
  pointer, ending the duration of the region of storage.
179