From Jason Turner

[basic.stc]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp3tiaebah/{from.md → to.md} +58 -116
tmp/tmp3tiaebah/{from.md → to.md} RENAMED
@@ -1,7 +1,9 @@
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
 
@@ -21,33 +23,35 @@ When the end of the duration of a region of storage is reached, the
21
  values of all pointers representing the address of any part of that
22
  region of storage become invalid pointer values [[basic.compound]].
23
  Indirection through an invalid pointer value and passing an invalid
24
  pointer value to a deallocation function have undefined behavior. Any
25
  other use of an invalid pointer value has *implementation-defined*
26
- behavior.[^13]
27
 
28
  #### Static storage duration <a id="basic.stc.static">[[basic.stc.static]]</a>
29
 
30
- All variables which do not have dynamic storage duration, do not have
31
- thread storage duration, and are not local have *static storage
32
- duration*. The storage for these entities lasts for the duration of the
33
- program ([[basic.start.static]], [[basic.start.term]]).
 
 
 
 
 
34
 
35
  If a variable with static storage duration has initialization or a
36
  destructor with side effects, it shall not be eliminated even if it
37
  appears to be unused, except that a class object or its copy/move may be
38
  eliminated as specified in  [[class.copy.elision]].
39
 
40
- The keyword `static` can be used to declare a local variable with static
41
- storage duration.
42
-
43
- [*Note 1*: [[stmt.dcl]] describes the initialization of local `static`
44
- variables; [[basic.start.term]] describes the destruction of local
45
- `static` variables. — *end note*]
46
-
47
- The keyword `static` applied to a class data member in a class
48
- definition gives the data member static storage duration.
49
 
50
  #### Thread storage duration <a id="basic.stc.thread">[[basic.stc.thread]]</a>
51
 
52
  All variables declared with the `thread_local` keyword have
53
  *thread storage duration*. The storage for these entities lasts for the
@@ -60,13 +64,14 @@ specified in  [[basic.start.static]], [[basic.start.dynamic]], and
60
  [[stmt.dcl]] and, if constructed, is destroyed on thread exit
61
  [[basic.start.term]]. — *end note*]
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
@@ -75,30 +80,33 @@ 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.elision]].
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 destroyed
82
  using *delete-expression*s [[expr.delete]]. A C++ implementation
83
  provides access to, and management of, dynamic storage via the global
84
- *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 at
95
- most one definition of a replaceable allocation or deallocation
96
- function. Any such function definition replaces the default version
97
- provided in the library [[replacement.functions]]. The following
98
- allocation and deallocation functions [[support.dynamic]] are implicitly
99
- declared in global scope in each translation unit of a program.
 
100
 
101
  ``` cpp
102
  [[nodiscard]] void* operator new(std::size_t);
103
  [[nodiscard]] void* operator new(std::size_t, std::align_val_t);
104
 
@@ -114,22 +122,24 @@ void operator delete[](void*) noexcept;
114
  void operator delete[](void*, std::size_t) noexcept;
115
  void operator delete[](void*, std::align_val_t) noexcept;
116
  void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
117
  ```
118
 
119
- These implicit declarations introduce only the function names `operator`
120
- `new`, `operator` `new[]`, `operator` `delete`, and `operator`
121
- `delete[]`.
122
 
123
  [*Note 2*: The implicit declarations do not introduce the names `std`,
124
  `std::size_t`, `std::align_val_t`, or any other names that the library
125
  uses to declare these names. Thus, a *new-expression*,
126
  *delete-expression*, or function call that refers to one of these
127
- functions without importing or including the header `<new>` is
128
- well-formed. However, referring to `std` or `std::size_t` or
129
- `std::align_val_t` is ill-formed unless the name has been declared by
130
- importing or including the appropriate header. — *end note*]
 
 
131
 
132
  Allocation and/or deallocation functions may also be declared and
133
  defined for any class [[class.free]].
134
 
135
  If the behavior of an allocation or deallocation function does not
@@ -137,22 +147,21 @@ satisfy the semantic constraints specified in 
137
  [[basic.stc.dynamic.allocation]] and 
138
  [[basic.stc.dynamic.deallocation]], the behavior is undefined.
139
 
140
  ##### Allocation functions <a id="basic.stc.dynamic.allocation">[[basic.stc.dynamic.allocation]]</a>
141
 
142
- An allocation function shall be a class member function or a global
143
- function; a program is ill-formed if an allocation function is declared
144
- in a namespace scope other than global scope or declared static in
145
- global scope. The return type shall be `void*`. The first parameter
146
- shall have type `std::size_t` [[support.types]]. The first parameter
147
- shall not have an associated default argument [[dcl.fct.default]]. The
148
- value of the first parameter is interpreted as the requested size of the
149
- allocation. An allocation function can be a function template. Such a
150
- template shall declare its return type and first parameter as specified
151
- above (that is, template parameter types shall not be used in the return
152
- type and first parameter type). Template allocation functions shall have
153
- two or more parameters.
154
 
155
  An allocation function attempts to allocate the requested amount of
156
  storage. If it is successful, it returns the address of the start of a
157
  block of storage whose length in bytes is at least as large as the
158
  requested size. The order, contiguity, and initial value of storage
@@ -164,11 +173,11 @@ from any previously returned value `p1`, unless that value `p1` was
164
  subsequently passed to a replaceable deallocation function. Furthermore,
165
  for the library allocation functions in  [[new.delete.single]] and 
166
  [[new.delete.array]], `p0` represents the address of a block of storage
167
  disjoint from the storage for any other object accessible to the caller.
168
  The effect of indirecting through a pointer returned from a request for
169
- zero size is undefined.[^14]
170
 
171
  For an allocation function other than a reserved placement allocation
172
  function [[new.delete.placement]], the pointer returned on a successful
173
  call shall represent the address of storage that is aligned as follows:
174
 
@@ -208,14 +217,12 @@ duration [[basic.stc.thread]], for objects of type `std::type_info`
208
  [[expr.typeid]], or for an exception object
209
  [[except.throw]]. — *end note*]
210
 
211
  ##### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
212
 
213
- Deallocation functions shall be class member functions or global
214
- functions; a program is ill-formed if deallocation functions are
215
- declared in a namespace scope other than global scope or declared static
216
- in global scope.
217
 
218
  A deallocation function is a *destroying operator delete* if it has at
219
  least two parameters and its second parameter is of type
220
  `std::destroying_delete_t`. A destroying operator delete shall be a
221
  class member function named `operator delete`.
@@ -229,11 +236,11 @@ first parameter shall be `C*`; otherwise, the type of its first
229
  parameter shall be `void*`. A deallocation function may have more than
230
  one parameter. A *usual deallocation function* is a deallocation
231
  function whose parameters after the first are
232
 
233
  - optionally, a parameter of type `std::destroying_delete_t`, then
234
- - optionally, a parameter of type `std::size_t` [^15], then
235
  - optionally, a parameter of type `std::align_val_t`.
236
 
237
  A destroying operator delete shall be a usual deallocation function. A
238
  deallocation function may be an instance of a function template. Neither
239
  the first parameter nor the return type shall depend on a template
@@ -250,75 +257,10 @@ has no effect.
250
  If the argument given to a deallocation function in the standard library
251
  is a pointer that is not the null pointer value [[basic.compound]], the
252
  deallocation function shall deallocate the storage referenced by the
253
  pointer, ending the duration of the region of storage.
254
 
255
- ##### Safely-derived pointers <a id="basic.stc.dynamic.safety">[[basic.stc.dynamic.safety]]</a>
256
-
257
- A *traceable pointer object* is
258
-
259
- - an object of an object pointer type [[basic.compound]], or
260
- - an object of an integral type that is at least as large as
261
- `std::intptr_t`, or
262
- - a sequence of elements in an array of narrow character type
263
- [[basic.fundamental]], where the size and alignment of the sequence
264
- match those of some object pointer type.
265
-
266
- A pointer value is a *safely-derived pointer* to an object with dynamic
267
- storage duration only if the pointer value has an object pointer type
268
- and is one of the following:
269
-
270
- - the value returned by a call to the C++ standard library
271
- implementation of `::operator new(std::{}size_t)` or
272
- `::operator new(std::size_t, std::align_val_t)` ;[^16]
273
- - the result of taking the address of an object (or one of its
274
- subobjects) designated by an lvalue resulting from indirection through
275
- a safely-derived pointer value;
276
- - the result of well-defined pointer arithmetic [[expr.add]] using a
277
- safely-derived pointer value;
278
- - the result of a well-defined pointer conversion ([[conv.ptr]],
279
- [[expr.type.conv]], [[expr.static.cast]], [[expr.cast]]) of a
280
- safely-derived pointer value;
281
- - the result of a `reinterpret_cast` of a safely-derived pointer value;
282
- - the result of a `reinterpret_cast` of an integer representation of a
283
- safely-derived pointer value;
284
- - the value of an object whose value was copied from a traceable pointer
285
- object, where at the time of the copy the source object contained a
286
- copy of a safely-derived pointer value.
287
-
288
- An integer value is an *integer representation of a safely-derived
289
- pointer* only if its type is at least as large as `std::intptr_t` and it
290
- is one of the following:
291
-
292
- - the result of a `reinterpret_cast` of a safely-derived pointer value;
293
- - the result of a valid conversion of an integer representation of a
294
- safely-derived pointer value;
295
- - the value of an object whose value was copied from a traceable pointer
296
- object, where at the time of the copy the source object contained an
297
- integer representation of a safely-derived pointer value;
298
- - the result of an additive or bitwise operation, one of whose operands
299
- is an integer representation of a safely-derived pointer value `P`, if
300
- that result converted by `reinterpret_cast<void*>` would compare equal
301
- to a safely-derived pointer computable from
302
- `reinterpret_cast<void*>(P)`.
303
-
304
- An implementation may have *relaxed pointer safety*, in which case the
305
- validity of a pointer value does not depend on whether it is a
306
- safely-derived pointer value. Alternatively, an implementation may have
307
- *strict pointer safety*, in which case a pointer value referring to an
308
- object with dynamic storage duration that is not a safely-derived
309
- pointer value is an invalid pointer value unless the referenced complete
310
- object has previously been declared reachable [[util.dynamic.safety]].
311
-
312
- [*Note 6*: The effect of using an invalid pointer value (including
313
- passing it to a deallocation function) is undefined, see  [[basic.stc]].
314
- This is true even if the unsafely-derived pointer value might compare
315
- equal to some safely-derived pointer value. — *end note*]
316
-
317
- It is *implementation-defined* whether an implementation has relaxed or
318
- strict pointer safety.
319
-
320
  #### Duration of subobjects <a id="basic.stc.inherit">[[basic.stc.inherit]]</a>
321
 
322
  The storage duration of subobjects and reference members is that of
323
  their complete object [[intro.object]].
324
 
 
1
  ### Storage duration <a id="basic.stc">[[basic.stc]]</a>
2
 
3
+ #### General <a id="basic.stc.general">[[basic.stc.general]]</a>
4
+
5
  The *storage duration* is the property of an object that defines the
6
  minimum potential lifetime of the storage containing the object. The
7
  storage duration is determined by the construct used to create the
8
  object and is one of the following:
9
 
 
23
  values of all pointers representing the address of any part of that
24
  region of storage become invalid pointer values [[basic.compound]].
25
  Indirection through an invalid pointer value and passing an invalid
26
  pointer value to a deallocation function have undefined behavior. Any
27
  other use of an invalid pointer value has *implementation-defined*
28
+ behavior.[^10]
29
 
30
  #### Static storage duration <a id="basic.stc.static">[[basic.stc.static]]</a>
31
 
32
+ All variables which
33
+
34
+ - do not have thread storage duration and
35
+ - belong to a namespace scope [[basic.scope.namespace]] or are first
36
+ declared with the `static` or `extern` keywords [[dcl.stc]]
37
+
38
+ have *static storage duration*. The storage for these entities lasts for
39
+ the duration of the program
40
+ [[basic.start.static]], [[basic.start.term]].
41
 
42
  If a variable with static storage duration has initialization or a
43
  destructor with side effects, it shall not be eliminated even if it
44
  appears to be unused, except that a class object or its copy/move may be
45
  eliminated as specified in  [[class.copy.elision]].
46
 
47
+ [*Note 1*: The keyword `static` can be used to declare a block
48
+ variable [[basic.scope.block]] with static storage duration;
49
+ [[stmt.dcl]] and [[basic.start.term]] describe the initialization and
50
+ destruction of such variables. The keyword `static` applied to a class
51
+ data member in a class definition gives the data member static storage
52
+ duration [[class.static.data]]. — *end note*]
 
 
 
53
 
54
  #### Thread storage duration <a id="basic.stc.thread">[[basic.stc.thread]]</a>
55
 
56
  All variables declared with the `thread_local` keyword have
57
  *thread storage duration*. The storage for these entities lasts for the
 
64
  [[stmt.dcl]] and, if constructed, is destroyed on thread exit
65
  [[basic.start.term]]. — *end note*]
66
 
67
  #### Automatic storage duration <a id="basic.stc.auto">[[basic.stc.auto]]</a>
68
 
69
+ Variables that belong to a block or parameter scope and are not
70
+ explicitly declared `static`, `thread_local`, or `extern` have
71
+ *automatic storage duration*. The storage for these entities lasts until
72
+ the block in which they are created exits.
73
 
74
  [*Note 1*: These variables are initialized and destroyed as described
75
  in  [[stmt.dcl]]. — *end note*]
76
 
77
  If a variable with automatic storage duration has initialization or a
 
80
  it appears to be unused, except that a class object or its copy/move may
81
  be eliminated as specified in  [[class.copy.elision]].
82
 
83
  #### Dynamic storage duration <a id="basic.stc.dynamic">[[basic.stc.dynamic]]</a>
84
 
85
+ ##### General <a id="basic.stc.dynamic.general">[[basic.stc.dynamic.general]]</a>
86
+
87
  Objects can be created dynamically during program execution
88
  [[intro.execution]], using *new-expression*s [[expr.new]], and destroyed
89
  using *delete-expression*s [[expr.delete]]. A C++ implementation
90
  provides access to, and management of, dynamic storage via the global
91
+ *allocation functions* `operator new` and `operator new[]` and the
92
+ global *deallocation functions* `operator delete` and
93
+ `operator delete[]`.
94
 
95
  [*Note 1*: The non-allocating forms described in
96
  [[new.delete.placement]] do not perform allocation or
97
  deallocation. — *end note*]
98
 
99
  The library provides default definitions for the global allocation and
100
  deallocation functions. Some global allocation and deallocation
101
+ functions are replaceable [[new.delete]]; these are attached to the
102
+ global module [[module.unit]]. A C++ program shall provide at most one
103
+ definition of a replaceable allocation or deallocation function. Any
104
+ such function definition replaces the default version provided in the
105
+ library [[replacement.functions]]. The following allocation and
106
+ deallocation functions [[support.dynamic]] are implicitly declared in
107
+ global scope in each translation unit of a program.
108
 
109
  ``` cpp
110
  [[nodiscard]] void* operator new(std::size_t);
111
  [[nodiscard]] void* operator new(std::size_t, std::align_val_t);
112
 
 
122
  void operator delete[](void*, std::size_t) noexcept;
123
  void operator delete[](void*, std::align_val_t) noexcept;
124
  void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
125
  ```
126
 
127
+ These implicit declarations introduce only the function names
128
+ `operator new`, `operator new[]`, `operator delete`, and
129
+ `operator delete[]`.
130
 
131
  [*Note 2*: The implicit declarations do not introduce the names `std`,
132
  `std::size_t`, `std::align_val_t`, or any other names that the library
133
  uses to declare these names. Thus, a *new-expression*,
134
  *delete-expression*, or function call that refers to one of these
135
+ functions without importing or including the header `<new>` or importing
136
+ a C++ library module [[std.modules]] is well-formed. However, referring
137
+ to `std` or `std::size_t` or `std::align_val_t` is ill-formed unless a
138
+ standard library declaration
139
+ [[cstddef.syn]], [[new.syn]], [[std.modules]] of that name precedes
140
+ [[basic.lookup.general]] the use of that name. — *end note*]
141
 
142
  Allocation and/or deallocation functions may also be declared and
143
  defined for any class [[class.free]].
144
 
145
  If the behavior of an allocation or deallocation function does not
 
147
  [[basic.stc.dynamic.allocation]] and 
148
  [[basic.stc.dynamic.deallocation]], the behavior is undefined.
149
 
150
  ##### Allocation functions <a id="basic.stc.dynamic.allocation">[[basic.stc.dynamic.allocation]]</a>
151
 
152
+ An allocation function that is not a class member function shall belong
153
+ to the global scope and not have a name with internal linkage. The
154
+ return type shall be `void*`. The first parameter shall have type
155
+ `std::size_t` [[support.types]]. The first parameter shall not have an
156
+ associated default argument [[dcl.fct.default]]. The value of the first
157
+ parameter is interpreted as the requested size of the allocation. An
158
+ allocation function can be a function template. Such a template shall
159
+ declare its return type and first parameter as specified above (that is,
160
+ template parameter types shall not be used in the return type and first
161
+ parameter type). Allocation function templates shall have two or more
162
+ parameters.
 
163
 
164
  An allocation function attempts to allocate the requested amount of
165
  storage. If it is successful, it returns the address of the start of a
166
  block of storage whose length in bytes is at least as large as the
167
  requested size. The order, contiguity, and initial value of storage
 
173
  subsequently passed to a replaceable deallocation function. Furthermore,
174
  for the library allocation functions in  [[new.delete.single]] and 
175
  [[new.delete.array]], `p0` represents the address of a block of storage
176
  disjoint from the storage for any other object accessible to the caller.
177
  The effect of indirecting through a pointer returned from a request for
178
+ zero size is undefined.[^11]
179
 
180
  For an allocation function other than a reserved placement allocation
181
  function [[new.delete.placement]], the pointer returned on a successful
182
  call shall represent the address of storage that is aligned as follows:
183
 
 
217
  [[expr.typeid]], or for an exception object
218
  [[except.throw]]. — *end note*]
219
 
220
  ##### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
221
 
222
+ A deallocation function that is not a class member function shall belong
223
+ to the global scope and not have a name with internal linkage.
 
 
224
 
225
  A deallocation function is a *destroying operator delete* if it has at
226
  least two parameters and its second parameter is of type
227
  `std::destroying_delete_t`. A destroying operator delete shall be a
228
  class member function named `operator delete`.
 
236
  parameter shall be `void*`. A deallocation function may have more than
237
  one parameter. A *usual deallocation function* is a deallocation
238
  function whose parameters after the first are
239
 
240
  - optionally, a parameter of type `std::destroying_delete_t`, then
241
+ - optionally, a parameter of type `std::size_t`,[^12] then
242
  - optionally, a parameter of type `std::align_val_t`.
243
 
244
  A destroying operator delete shall be a usual deallocation function. A
245
  deallocation function may be an instance of a function template. Neither
246
  the first parameter nor the return type shall depend on a template
 
257
  If the argument given to a deallocation function in the standard library
258
  is a pointer that is not the null pointer value [[basic.compound]], the
259
  deallocation function shall deallocate the storage referenced by the
260
  pointer, ending the duration of the region of storage.
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  #### Duration of subobjects <a id="basic.stc.inherit">[[basic.stc.inherit]]</a>
263
 
264
  The storage duration of subobjects and reference members is that of
265
  their complete object [[intro.object]].
266