From Jason Turner

[basic.stc]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpwu8bf_3v/{from.md → to.md} +32 -35
tmp/tmpwu8bf_3v/{from.md → to.md} RENAMED
@@ -10,24 +10,24 @@ object and is one of the following:
10
  - static storage duration
11
  - thread storage duration
12
  - automatic storage duration
13
  - dynamic storage duration
14
 
 
 
 
 
15
  Static, thread, and automatic storage durations are associated with
16
- objects introduced by declarations [[basic.def]] and implicitly created
17
- by the implementation [[class.temporary]]. The dynamic storage duration
18
- is associated with objects created by a *new-expression* [[expr.new]].
 
19
 
20
  The storage duration categories apply to references as well.
21
 
22
- When the end of the duration of a region of storage is reached, the
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
 
@@ -64,18 +64,22 @@ specified in  [[basic.start.static]], [[basic.start.dynamic]], and
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
78
  destructor with side effects, an implementation shall not destroy it
79
  before the end of its block nor eliminate it as an optimization, even if
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]].
@@ -96,29 +100,25 @@ global *deallocation functions* `operator delete` and
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
 
113
  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
- [[nodiscard]] void* operator new[](std::size_t);
119
- [[nodiscard]] void* operator new[](std::size_t, std::align_val_t);
120
 
121
  void operator delete[](void*) noexcept;
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;
@@ -173,11 +173,11 @@ from any previously returned value `p1`, unless that value `p1` was
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
 
@@ -192,12 +192,12 @@ call shall represent the address of storage that is aligned as follows:
192
 
193
  An allocation function that fails to allocate storage can invoke the
194
  currently installed new-handler function [[new.handler]], if any.
195
 
196
  [*Note 3*: A program-supplied allocation function can obtain the
197
- address of the currently installed `new_handler` using the
198
- `std::get_new_handler` function [[get.new.handler]]. — *end note*]
199
 
200
  An allocation function that has a non-throwing exception specification
201
  [[except.spec]] indicates failure by returning a null pointer value. Any
202
  other allocation function never returns a null pointer value and
203
  indicates failure only by throwing an exception [[except.throw]] of a
@@ -212,11 +212,13 @@ calls to the functions in the C++ standard library.
212
 
213
  [*Note 4*: In particular, a global allocation function is not called to
214
  allocate storage for objects with static storage duration
215
  [[basic.stc.static]], for objects or references with thread storage
216
  duration [[basic.stc.thread]], for objects of type `std::type_info`
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
@@ -236,11 +238,11 @@ first parameter shall be `C*`; otherwise, the type of its first
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,10 +259,5 @@ has no effect.
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
-
 
10
  - static storage duration
11
  - thread storage duration
12
  - automatic storage duration
13
  - dynamic storage duration
14
 
15
+ [*Note 1*: After the duration of a region of storage has ended, the use
16
+ of pointers to that region of storage is limited
17
+ [[basic.compound]]. — *end note*]
18
+
19
  Static, thread, and automatic storage durations are associated with
20
+ objects introduced by declarations [[basic.def]] and with temporary
21
+ objects [[class.temporary]]. The dynamic storage duration is associated
22
+ with objects created by a *new-expression* [[expr.new]] or with
23
+ implicitly created objects [[intro.object]].
24
 
25
  The storage duration categories apply to references as well.
26
 
27
+ The storage duration of subobjects and reference members is that of
28
+ their complete object [[intro.object]].
 
 
 
 
 
29
 
30
  #### Static storage duration <a id="basic.stc.static">[[basic.stc.static]]</a>
31
 
32
  All variables which
33
 
 
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 scope and are not explicitly declared
70
+ `static`, `thread_local`, or `extern` have *automatic storage duration*.
71
+ The storage for such variables lasts until the block in which they are
72
+ created exits.
73
 
74
  [*Note 1*: These variables are initialized and destroyed as described
75
  in  [[stmt.dcl]]. — *end note*]
76
 
77
+ Variables that belong to a parameter scope also have automatic storage
78
+ duration. The storage for a function parameter lasts until immediately
79
+ after its destruction [[expr.call]].
80
+
81
  If a variable with automatic storage duration has initialization or a
82
  destructor with side effects, an implementation shall not destroy it
83
  before the end of its block nor eliminate it as an optimization, even if
84
  it appears to be unused, except that a class object or its copy/move may
85
  be eliminated as specified in  [[class.copy.elision]].
 
100
  [[new.delete.placement]] do not perform allocation or
101
  deallocation. — *end note*]
102
 
103
  The library provides default definitions for the global allocation and
104
  deallocation functions. Some global allocation and deallocation
105
+ functions are replaceable [[term.replaceable.function]]. The following
106
+ allocation and deallocation functions [[support.dynamic]] are implicitly
107
+ declared in global scope in each translation unit of a program.
 
 
 
 
108
 
109
  ``` cpp
110
+ void* operator new(std::size_t);
111
+ void* operator new(std::size_t, std::align_val_t);
112
 
113
  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
+ void* operator new[](std::size_t);
119
+ void* operator new[](std::size_t, std::align_val_t);
120
 
121
  void operator delete[](void*) noexcept;
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;
 
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.[^9]
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
 
 
192
 
193
  An allocation function that fails to allocate storage can invoke the
194
  currently installed new-handler function [[new.handler]], if any.
195
 
196
  [*Note 3*: A program-supplied allocation function can obtain the
197
+ currently installed `new_handler` using the `std::get_new_handler`
198
+ function [[get.new.handler]]. — *end note*]
199
 
200
  An allocation function that has a non-throwing exception specification
201
  [[except.spec]] indicates failure by returning a null pointer value. Any
202
  other allocation function never returns a null pointer value and
203
  indicates failure only by throwing an exception [[except.throw]] of a
 
212
 
213
  [*Note 4*: In particular, a global allocation function is not called to
214
  allocate storage for objects with static storage duration
215
  [[basic.stc.static]], for objects or references with thread storage
216
  duration [[basic.stc.thread]], for objects of type `std::type_info`
217
+ [[expr.typeid]], for an object of type
218
+ `std::contracts::contract_violation` when a contract violation occurs
219
+ [[basic.contract.eval]], or for an exception object
220
  [[except.throw]]. — *end note*]
221
 
222
  ##### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
223
 
224
  A deallocation function that is not a class member function shall belong
 
238
  parameter shall be `void*`. A deallocation function may have more than
239
  one parameter. A *usual deallocation function* is a deallocation
240
  function whose parameters after the first are
241
 
242
  - optionally, a parameter of type `std::destroying_delete_t`, then
243
+ - optionally, a parameter of type `std::size_t`,[^10] then
244
  - optionally, a parameter of type `std::align_val_t`.
245
 
246
  A destroying operator delete shall be a usual deallocation function. A
247
  deallocation function may be an instance of a function template. Neither
248
  the first parameter nor the return type shall depend on a template
 
259
  If the argument given to a deallocation function in the standard library
260
  is a pointer that is not the null pointer value [[basic.compound]], the
261
  deallocation function shall deallocate the storage referenced by the
262
  pointer, ending the duration of the region of storage.
263