From Jason Turner

[basic.start]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpymuvtmz3/{from.md → to.md} +470 -98
tmp/tmpymuvtmz3/{from.md → to.md} RENAMED
@@ -1,98 +1,92 @@
1
- ## Start and termination <a id="basic.start">[[basic.start]]</a>
2
 
3
- ### `main` function <a id="basic.start.main">[[basic.start.main]]</a>
4
 
5
- A program shall contain a global function called `main`. Executing a
6
- program starts a main thread of execution ([[intro.multithread]],
7
- [[thread.threads]]) in which the `main` function is invoked, and in
8
- which variables of static storage duration might be initialized (
9
- [[basic.start.static]]) and destroyed ([[basic.start.term]]). It is
10
- *implementation-defined* whether a program in a freestanding environment
11
- is required to define a `main` function.
12
 
13
- [*Note 1*: In a freestanding environment, start-up and termination is
14
- *implementation-defined*; start-up contains the execution of
15
- constructors for objects of namespace scope with static storage
16
- duration; termination contains the execution of destructors for objects
17
- with static storage duration. — *end note*]
18
 
19
  An implementation shall not predefine the `main` function. This function
20
  shall not be overloaded. Its type shall have C++ language linkage and it
21
  shall have a declared return type of type `int`, but otherwise its type
22
  is *implementation-defined*. An implementation shall allow both
23
 
24
  - a function of `()` returning `int` and
25
  - a function of `(int`, pointer to pointer to `char)` returning `int`
26
 
27
- as the type of `main` ([[dcl.fct]]). In the latter form, for purposes
28
- of exposition, the first function parameter is called `argc` and the
29
- second function parameter is called `argv`, where `argc` shall be the
30
- number of arguments passed to the program from the environment in which
31
- the program is run. If `argc` is nonzero these arguments shall be
32
- supplied in `argv[0]` through `argv[argc-1]` as pointers to the initial
33
- characters of null-terminated multibyte strings (NTMBS s) (
34
- [[multibyte.strings]]) and `argv[0]` shall be the pointer to the initial
35
  character of a NTMBS that represents the name used to invoke the program
36
  or `""`. The value of `argc` shall be non-negative. The value of
37
  `argv[argc]` shall be 0.
38
 
39
  [*Note 2*: It is recommended that any further (optional) parameters be
40
  added after `argv`. — *end note*]
41
 
42
- The function `main` shall not be used within a program. The linkage (
43
- [[basic.link]]) of `main` is *implementation-defined*. A program that
44
  defines `main` as deleted or that declares `main` to be `inline`,
45
- `static`, or `constexpr` is ill-formed. The `main` function shall not be
46
- declared with a *linkage-specification* ([[dcl.link]]). A program that
47
- declares a variable `main` at global scope or that declares the name
48
- `main` with C language linkage (in any namespace) is ill-formed. The
49
- name `main` is not otherwise reserved.
 
 
50
 
51
  [*Example 1*: Member functions, classes, and enumerations can be called
52
  `main`, as can entities in other namespaces. — *end example*]
53
 
54
  Terminating the program without leaving the current block (e.g., by
55
- calling the function `std::exit(int)` ([[support.start.term]])) does
56
- not destroy any objects with automatic storage duration (
57
- [[class.dtor]]). If `std::exit` is called to end a program during the
58
- destruction of an object with static or thread storage duration, the
59
- program has undefined behavior.
60
 
61
- A return statement in `main` has the effect of leaving the main function
62
- (destroying any objects with automatic storage duration) and calling
63
- `std::exit` with the return value as the argument. If control flows off
64
- the end of the *compound-statement* of `main`, the effect is equivalent
65
- to a `return` with operand `0` (see also [[except.handle]]).
 
66
 
67
- ### Static initialization <a id="basic.start.static">[[basic.start.static]]</a>
68
 
69
  Variables with static storage duration are initialized as a consequence
70
  of program initiation. Variables with thread storage duration are
71
  initialized as a consequence of thread execution. Within each of these
72
  phases of initiation, initialization occurs as follows.
73
 
74
- A *constant initializer* for a variable or temporary object `o` is an
75
- initializer whose full-expression is a constant expression, except that
76
- if `o` is an object, such an initializer may also invoke constexpr
77
- constructors for `o` and its subobjects even if those objects are of
78
- non-literal class types.
79
-
80
- [*Note 1*: Such a class may have a non-trivial
81
- destructor. — *end note*]
82
-
83
  *Constant initialization* is performed if a variable or temporary object
84
- with static or thread storage duration is initialized by a constant
85
- initializer for the entity. If constant initialization is not performed,
86
- a variable with static storage duration ([[basic.stc.static]]) or
87
- thread storage duration ([[basic.stc.thread]]) is zero-initialized (
88
- [[dcl.init]]). Together, zero-initialization and constant initialization
89
- are called *static initialization*; all other initialization is *dynamic
90
- initialization*. All static initialization strongly happens before (
91
- [[intro.races]]) any dynamic initialization.
92
 
93
- [*Note 2*: The dynamic initialization of non-local variables is
94
  described in  [[basic.start.dynamic]]; that of local static variables is
95
  described in  [[stmt.dcl]]. — *end note*]
96
 
97
  An implementation is permitted to perform the initialization of a
98
  variable with static or thread storage duration as a static
@@ -105,11 +99,11 @@ statically, provided that
105
  - the static version of the initialization produces the same value in
106
  the initialized variable as would be produced by the dynamic
107
  initialization if all variables not required to be initialized
108
  statically were initialized dynamically.
109
 
110
- [*Note 3*:
111
 
112
  As a consequence, if the initialization of an object `obj1` refers to an
113
  object `obj2` of namespace scope potentially requiring dynamic
114
  initialization and defined later in the same translation unit, it is
115
  unspecified whether the value of `obj2` used will be the value of the
@@ -126,11 +120,11 @@ double d2 = d1; // unspecified:
126
  double d1 = fd(); // may be initialized statically or dynamically to 1.0
127
  ```
128
 
129
  — *end note*]
130
 
131
- ### Dynamic initialization of non-local variables <a id="basic.start.dynamic">[[basic.start.dynamic]]</a>
132
 
133
  Dynamic initialization of a non-local variable with static storage
134
  duration is unordered if the variable is an implicitly or explicitly
135
  instantiated specialization, is partially-ordered if the variable is an
136
  inline variable that is not an implicitly or explicitly instantiated
@@ -138,23 +132,33 @@ specialization, and otherwise is ordered.
138
 
139
  [*Note 1*: An explicitly specialized non-inline static data member or
140
  variable template specialization has ordered
141
  initialization. — *end note*]
142
 
 
 
 
 
 
 
 
 
143
  Dynamic initialization of non-local variables `V` and `W` with static
144
  storage duration are ordered as follows:
145
 
146
- - If `V` and `W` have ordered initialization and `V` is defined before
147
- `W` within a single translation unit, the initialization of `V` is
148
- sequenced before the initialization of `W`.
149
- - If `V` has partially-ordered initialization, `W` does not have
150
- unordered initialization, and `V` is defined before `W` in every
151
- translation unit in which `W` is defined, then
152
- - if the program starts a thread ([[intro.multithread]]) other than
153
- the main thread ([[basic.start.main]]), the initialization of `V`
154
- strongly happens before the initialization of `W`;
155
- - otherwise, the initialization of `V` is sequenced before the
 
 
156
  initialization of `W`.
157
  - Otherwise, if the program starts a thread other than the main thread
158
  before either `V` or `W` is initialized, it is unspecified in which
159
  threads the initializations of `V` and `W` occur; the initializations
160
  are unsequenced if they occur in the same thread.
@@ -162,20 +166,20 @@ storage duration are ordered as follows:
162
  sequenced.
163
 
164
  [*Note 2*: This definition permits initialization of a sequence of
165
  ordered variables concurrently with another sequence. — *end note*]
166
 
167
- A *non-initialization odr-use* is an odr-use ([[basic.def.odr]]) not
168
  caused directly or indirectly by the initialization of a non-local
169
  static or thread storage duration variable.
170
 
171
  It is *implementation-defined* whether the dynamic initialization of a
172
  non-local non-inline variable with static storage duration is sequenced
173
  before the first statement of `main` or is deferred. If it is deferred,
174
  it strongly happens before any non-initialization odr-use of any
175
  non-inline function or non-inline variable defined in the same
176
- translation unit as the variable to be initialized. [^11] It is
177
  *implementation-defined* in which threads and at which points in the
178
  program such deferred dynamic initialization occurs.
179
 
180
  [*Note 3*: Such points should be chosen in a way that allows the
181
  programmer to avoid deadlocks. — *end note*]
@@ -234,32 +238,29 @@ odr-use by *t* of any non-inline variable with thread storage duration
234
  defined in the same translation unit as the variable to be initialized.
235
  It is *implementation-defined* in which threads and at which points in
236
  the program such deferred dynamic initialization occurs.
237
 
238
  If the initialization of a non-local variable with static or thread
239
- storage duration exits via an exception, `std::terminate` is called (
240
- [[except.terminate]]).
241
 
242
- ### Termination <a id="basic.start.term">[[basic.start.term]]</a>
243
 
244
- Destructors ([[class.dtor]]) for initialized objects (that is, objects
245
- whose lifetime ([[basic.life]]) has begun) with static storage
246
- duration, and functions registered with `std::atexit`, are called as
247
- part of a call to `std::exit` ([[support.start.term]]). The call to
248
- `std::exit` is sequenced before the invocations of the destructors and
249
- the registered functions.
250
 
251
- [*Note 1*: Returning from `main` invokes `std::exit` (
252
- [[basic.start.main]]). — *end note*]
253
 
254
- Destructors for initialized objects with thread storage duration within
255
- a given thread are called as a result of returning from the initial
256
- function of that thread and as a result of that thread calling
257
- `std::exit`. The completions of the destructors for all initialized
258
- objects with thread storage duration within that thread strongly happen
259
- before the initiation of the destructors of any object with static
260
- storage duration.
261
 
262
  If the completion of the constructor or dynamic initialization of an
263
  object with static storage duration strongly happens before that of
264
  another, the completion of the destructor of the second is sequenced
265
  before the initiation of the destructor of the first. If the completion
@@ -270,12 +271,12 @@ destructor of the first. If an object is initialized statically, the
270
  object is destroyed in the same order as if the object was dynamically
271
  initialized. For an object of array or class type, all subobjects of
272
  that object are destroyed before any block-scope object with static
273
  storage duration initialized during the construction of the subobjects
274
  is destroyed. If the destruction of an object with static or thread
275
- storage duration exits via an exception, `std::terminate` is called (
276
- [[except.terminate]]).
277
 
278
  If a function contains a block-scope object of static or thread storage
279
  duration that has been destroyed and the function is called during the
280
  destruction of an object with static or thread storage duration, the
281
  program has undefined behavior if the flow of control passes through the
@@ -283,26 +284,26 @@ definition of the previously destroyed block-scope object. Likewise, the
283
  behavior is undefined if the block-scope object is used indirectly
284
  (i.e., through a pointer) after its destruction.
285
 
286
  If the completion of the initialization of an object with static storage
287
  duration strongly happens before a call to `std::atexit` (see
288
- `<cstdlib>`,  [[support.start.term]]), the call to the function passed
289
- to `std::atexit` is sequenced before the call to the destructor for the
290
  object. If a call to `std::atexit` strongly happens before the
291
  completion of the initialization of an object with static storage
292
  duration, the call to the destructor for the object is sequenced before
293
  the call to the function passed to `std::atexit`. If a call to
294
  `std::atexit` strongly happens before another call to `std::atexit`, the
295
  call to the function passed to the second `std::atexit` call is
296
  sequenced before the call to the function passed to the first
297
  `std::atexit` call.
298
 
299
  If there is a use of a standard library object or function not permitted
300
- within signal handlers ([[support.runtime]]) that does not happen
301
- before ([[intro.multithread]]) completion of destruction of objects
302
- with static storage duration and execution of `std::atexit` registered
303
- functions ([[support.start.term]]), the program has undefined behavior.
304
 
305
  [*Note 2*: If there is a use of an object with static storage duration
306
  that does not happen before the object’s destruction, the program has
307
  undefined behavior. Terminating every thread before a call to
308
  `std::exit` or the exit from `main` is sufficient, but not necessary, to
@@ -311,5 +312,376 @@ static-storage-duration objects. — *end note*]
311
 
312
  Calling the function `std::abort()` declared in `<cstdlib>` terminates
313
  the program without executing any destructors and without calling the
314
  functions passed to `std::atexit()` or `std::at_quick_exit()`.
315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Start and termination <a id="basic.start">[[basic.start]]</a>
2
 
3
+ #### `main` function <a id="basic.start.main">[[basic.start.main]]</a>
4
 
5
+ A program shall contain a global function called `main` attached to the
6
+ global module. Executing a program starts a main thread of execution (
7
+ [[intro.multithread]], [[thread.threads]]) in which the `main` function
8
+ is invoked, and in which variables of static storage duration might be
9
+ initialized [[basic.start.static]] and destroyed [[basic.start.term]].
10
+ It is *implementation-defined* whether a program in a freestanding
11
+ environment is required to define a `main` function.
12
 
13
+ [*Note 1*: In a freestanding environment, startup and termination is
14
+ *implementation-defined*; startup contains the execution of constructors
15
+ for objects of namespace scope with static storage duration; termination
16
+ contains the execution of destructors for objects with static storage
17
+ duration. — *end note*]
18
 
19
  An implementation shall not predefine the `main` function. This function
20
  shall not be overloaded. Its type shall have C++ language linkage and it
21
  shall have a declared return type of type `int`, but otherwise its type
22
  is *implementation-defined*. An implementation shall allow both
23
 
24
  - a function of `()` returning `int` and
25
  - a function of `(int`, pointer to pointer to `char)` returning `int`
26
 
27
+ as the type of `main` [[dcl.fct]]. In the latter form, for purposes of
28
+ exposition, the first function parameter is called `argc` and the second
29
+ function parameter is called `argv`, where `argc` shall be the number of
30
+ arguments passed to the program from the environment in which the
31
+ program is run. If `argc` is nonzero these arguments shall be supplied
32
+ in `argv[0]` through `argv[argc-1]` as pointers to the initial
33
+ characters of null-terminated multibyte strings (NTMBSs)
34
+ [[multibyte.strings]] and `argv[0]` shall be the pointer to the initial
35
  character of a NTMBS that represents the name used to invoke the program
36
  or `""`. The value of `argc` shall be non-negative. The value of
37
  `argv[argc]` shall be 0.
38
 
39
  [*Note 2*: It is recommended that any further (optional) parameters be
40
  added after `argv`. — *end note*]
41
 
42
+ The function `main` shall not be used within a program. The linkage
43
+ [[basic.link]] of `main` is *implementation-defined*. A program that
44
  defines `main` as deleted or that declares `main` to be `inline`,
45
+ `static`, or `constexpr` is ill-formed. The function `main` shall not be
46
+ a coroutine [[dcl.fct.def.coroutine]]. The `main` function shall not be
47
+ declared with a *linkage-specification* [[dcl.link]]. A program that
48
+ declares a variable `main` at global scope, or that declares a function
49
+ `main` at global scope attached to a named module, or that declares the
50
+ name `main` with C language linkage (in any namespace) is ill-formed.
51
+ The name `main` is not otherwise reserved.
52
 
53
  [*Example 1*: Member functions, classes, and enumerations can be called
54
  `main`, as can entities in other namespaces. — *end example*]
55
 
56
  Terminating the program without leaving the current block (e.g., by
57
+ calling the function `std::exit(int)` [[support.start.term]]) does not
58
+ destroy any objects with automatic storage duration [[class.dtor]]. If
59
+ `std::exit` is called to end a program during the destruction of an
60
+ object with static or thread storage duration, the program has undefined
61
+ behavior.
62
 
63
+ A `return` statement [[stmt.return]] in `main` has the effect of leaving
64
+ the main function (destroying any objects with automatic storage
65
+ duration) and calling `std::exit` with the return value as the argument.
66
+ If control flows off the end of the *compound-statement* of `main`, the
67
+ effect is equivalent to a `return` with operand `0` (see also
68
+ [[except.handle]]).
69
 
70
+ #### Static initialization <a id="basic.start.static">[[basic.start.static]]</a>
71
 
72
  Variables with static storage duration are initialized as a consequence
73
  of program initiation. Variables with thread storage duration are
74
  initialized as a consequence of thread execution. Within each of these
75
  phases of initiation, initialization occurs as follows.
76
 
 
 
 
 
 
 
 
 
 
77
  *Constant initialization* is performed if a variable or temporary object
78
+ with static or thread storage duration is constant-initialized
79
+ [[expr.const]]. If constant initialization is not performed, a variable
80
+ with static storage duration [[basic.stc.static]] or thread storage
81
+ duration [[basic.stc.thread]] is zero-initialized [[dcl.init]].
82
+ Together, zero-initialization and constant initialization are called
83
+ *static initialization*; all other initialization is *dynamic
84
+ initialization*. All static initialization strongly happens before
85
+ [[intro.races]] any dynamic initialization.
86
 
87
+ [*Note 1*: The dynamic initialization of non-local variables is
88
  described in  [[basic.start.dynamic]]; that of local static variables is
89
  described in  [[stmt.dcl]]. — *end note*]
90
 
91
  An implementation is permitted to perform the initialization of a
92
  variable with static or thread storage duration as a static
 
99
  - the static version of the initialization produces the same value in
100
  the initialized variable as would be produced by the dynamic
101
  initialization if all variables not required to be initialized
102
  statically were initialized dynamically.
103
 
104
+ [*Note 2*:
105
 
106
  As a consequence, if the initialization of an object `obj1` refers to an
107
  object `obj2` of namespace scope potentially requiring dynamic
108
  initialization and defined later in the same translation unit, it is
109
  unspecified whether the value of `obj2` used will be the value of the
 
120
  double d1 = fd(); // may be initialized statically or dynamically to 1.0
121
  ```
122
 
123
  — *end note*]
124
 
125
+ #### Dynamic initialization of non-local variables <a id="basic.start.dynamic">[[basic.start.dynamic]]</a>
126
 
127
  Dynamic initialization of a non-local variable with static storage
128
  duration is unordered if the variable is an implicitly or explicitly
129
  instantiated specialization, is partially-ordered if the variable is an
130
  inline variable that is not an implicitly or explicitly instantiated
 
132
 
133
  [*Note 1*: An explicitly specialized non-inline static data member or
134
  variable template specialization has ordered
135
  initialization. — *end note*]
136
 
137
+ A declaration `D` is *appearance-ordered* before a declaration `E` if
138
+
139
+ - `D` appears in the same translation unit as `E`, or
140
+ - the translation unit containing `E` has an interface dependency on the
141
+ translation unit containing `D`,
142
+
143
+ in either case prior to `E`.
144
+
145
  Dynamic initialization of non-local variables `V` and `W` with static
146
  storage duration are ordered as follows:
147
 
148
+ - If `V` and `W` have ordered initialization and the definition of `V`
149
+ is appearance-ordered before the definition of `W`, or if `V` has
150
+ partially-ordered initialization, `W` does not have unordered
151
+ initialization, and for every definition `E` of `W` there exists a
152
+ definition `D` of `V` such that `D` is appearance-ordered before `E`,
153
+ then
154
+ - if the program does not start a thread [[intro.multithread]] other
155
+ than the main thread [[basic.start.main]] or `V` and `W` have
156
+ ordered initialization and they are defined in the same translation
157
+ unit, the initialization of `V` is sequenced before the
158
+ initialization of `W`;
159
+ - otherwise, the initialization of `V` strongly happens before the
160
  initialization of `W`.
161
  - Otherwise, if the program starts a thread other than the main thread
162
  before either `V` or `W` is initialized, it is unspecified in which
163
  threads the initializations of `V` and `W` occur; the initializations
164
  are unsequenced if they occur in the same thread.
 
166
  sequenced.
167
 
168
  [*Note 2*: This definition permits initialization of a sequence of
169
  ordered variables concurrently with another sequence. — *end note*]
170
 
171
+ A *non-initialization odr-use* is an odr-use [[basic.def.odr]] not
172
  caused directly or indirectly by the initialization of a non-local
173
  static or thread storage duration variable.
174
 
175
  It is *implementation-defined* whether the dynamic initialization of a
176
  non-local non-inline variable with static storage duration is sequenced
177
  before the first statement of `main` or is deferred. If it is deferred,
178
  it strongly happens before any non-initialization odr-use of any
179
  non-inline function or non-inline variable defined in the same
180
+ translation unit as the variable to be initialized. [^29] It is
181
  *implementation-defined* in which threads and at which points in the
182
  program such deferred dynamic initialization occurs.
183
 
184
  [*Note 3*: Such points should be chosen in a way that allows the
185
  programmer to avoid deadlocks. — *end note*]
 
238
  defined in the same translation unit as the variable to be initialized.
239
  It is *implementation-defined* in which threads and at which points in
240
  the program such deferred dynamic initialization occurs.
241
 
242
  If the initialization of a non-local variable with static or thread
243
+ storage duration exits via an exception, the function `std::terminate`
244
+ is called [[except.terminate]].
245
 
246
+ #### Termination <a id="basic.start.term">[[basic.start.term]]</a>
247
 
248
+ Constructed objects [[dcl.init]] with static storage duration are
249
+ destroyed and functions registered with `std::atexit` are called as part
250
+ of a call to `std::exit` [[support.start.term]]. The call to `std::exit`
251
+ is sequenced before the destructions and the registered functions.
 
 
252
 
253
+ [*Note 1*: Returning from `main` invokes `std::exit`
254
+ [[basic.start.main]]. — *end note*]
255
 
256
+ Constructed objects with thread storage duration within a given thread
257
+ are destroyed as a result of returning from the initial function of that
258
+ thread and as a result of that thread calling `std::exit`. The
259
+ destruction of all constructed objects with thread storage duration
260
+ within that thread strongly happens before destroying any object with
261
+ static storage duration.
 
262
 
263
  If the completion of the constructor or dynamic initialization of an
264
  object with static storage duration strongly happens before that of
265
  another, the completion of the destructor of the second is sequenced
266
  before the initiation of the destructor of the first. If the completion
 
271
  object is destroyed in the same order as if the object was dynamically
272
  initialized. For an object of array or class type, all subobjects of
273
  that object are destroyed before any block-scope object with static
274
  storage duration initialized during the construction of the subobjects
275
  is destroyed. If the destruction of an object with static or thread
276
+ storage duration exits via an exception, the function `std::terminate`
277
+ is called [[except.terminate]].
278
 
279
  If a function contains a block-scope object of static or thread storage
280
  duration that has been destroyed and the function is called during the
281
  destruction of an object with static or thread storage duration, the
282
  program has undefined behavior if the flow of control passes through the
 
284
  behavior is undefined if the block-scope object is used indirectly
285
  (i.e., through a pointer) after its destruction.
286
 
287
  If the completion of the initialization of an object with static storage
288
  duration strongly happens before a call to `std::atexit` (see
289
+ `<cstdlib>`, [[support.start.term]]), the call to the function passed to
290
+ `std::atexit` is sequenced before the call to the destructor for the
291
  object. If a call to `std::atexit` strongly happens before the
292
  completion of the initialization of an object with static storage
293
  duration, the call to the destructor for the object is sequenced before
294
  the call to the function passed to `std::atexit`. If a call to
295
  `std::atexit` strongly happens before another call to `std::atexit`, the
296
  call to the function passed to the second `std::atexit` call is
297
  sequenced before the call to the function passed to the first
298
  `std::atexit` call.
299
 
300
  If there is a use of a standard library object or function not permitted
301
+ within signal handlers [[support.runtime]] that does not happen before
302
+ [[intro.multithread]] completion of destruction of objects with static
303
+ storage duration and execution of `std::atexit` registered functions
304
+ [[support.start.term]], the program has undefined behavior.
305
 
306
  [*Note 2*: If there is a use of an object with static storage duration
307
  that does not happen before the object’s destruction, the program has
308
  undefined behavior. Terminating every thread before a call to
309
  `std::exit` or the exit from `main` is sufficient, but not necessary, to
 
312
 
313
  Calling the function `std::abort()` declared in `<cstdlib>` terminates
314
  the program without executing any destructors and without calling the
315
  functions passed to `std::atexit()` or `std::at_quick_exit()`.
316
 
317
+ <!-- Link reference definitions -->
318
+ [allocator.members]: utilities.md#allocator.members
319
+ [allocator.traits.members]: utilities.md#allocator.traits.members
320
+ [atomics]: atomics.md#atomics
321
+ [atomics.flag]: atomics.md#atomics.flag
322
+ [atomics.lockfree]: atomics.md#atomics.lockfree
323
+ [atomics.order]: atomics.md#atomics.order
324
+ [bad.alloc]: support.md#bad.alloc
325
+ [basic]: #basic
326
+ [basic.align]: #basic.align
327
+ [basic.compound]: #basic.compound
328
+ [basic.def]: #basic.def
329
+ [basic.def.odr]: #basic.def.odr
330
+ [basic.exec]: #basic.exec
331
+ [basic.fundamental]: #basic.fundamental
332
+ [basic.fundamental.width]: #basic.fundamental.width
333
+ [basic.funscope]: #basic.funscope
334
+ [basic.indet]: #basic.indet
335
+ [basic.life]: #basic.life
336
+ [basic.link]: #basic.link
337
+ [basic.lookup]: #basic.lookup
338
+ [basic.lookup.argdep]: #basic.lookup.argdep
339
+ [basic.lookup.classref]: #basic.lookup.classref
340
+ [basic.lookup.elab]: #basic.lookup.elab
341
+ [basic.lookup.qual]: #basic.lookup.qual
342
+ [basic.lookup.udir]: #basic.lookup.udir
343
+ [basic.lookup.unqual]: #basic.lookup.unqual
344
+ [basic.lval]: expr.md#basic.lval
345
+ [basic.memobj]: #basic.memobj
346
+ [basic.namespace]: dcl.md#basic.namespace
347
+ [basic.pre]: #basic.pre
348
+ [basic.scope]: #basic.scope
349
+ [basic.scope.block]: #basic.scope.block
350
+ [basic.scope.class]: #basic.scope.class
351
+ [basic.scope.declarative]: #basic.scope.declarative
352
+ [basic.scope.enum]: #basic.scope.enum
353
+ [basic.scope.hiding]: #basic.scope.hiding
354
+ [basic.scope.namespace]: #basic.scope.namespace
355
+ [basic.scope.param]: #basic.scope.param
356
+ [basic.scope.pdecl]: #basic.scope.pdecl
357
+ [basic.scope.temp]: #basic.scope.temp
358
+ [basic.start]: #basic.start
359
+ [basic.start.dynamic]: #basic.start.dynamic
360
+ [basic.start.main]: #basic.start.main
361
+ [basic.start.static]: #basic.start.static
362
+ [basic.start.term]: #basic.start.term
363
+ [basic.stc]: #basic.stc
364
+ [basic.stc.auto]: #basic.stc.auto
365
+ [basic.stc.dynamic]: #basic.stc.dynamic
366
+ [basic.stc.dynamic.allocation]: #basic.stc.dynamic.allocation
367
+ [basic.stc.dynamic.deallocation]: #basic.stc.dynamic.deallocation
368
+ [basic.stc.dynamic.safety]: #basic.stc.dynamic.safety
369
+ [basic.stc.inherit]: #basic.stc.inherit
370
+ [basic.stc.static]: #basic.stc.static
371
+ [basic.stc.thread]: #basic.stc.thread
372
+ [basic.type.qualifier]: #basic.type.qualifier
373
+ [basic.type.qualifier.rel]: #basic.type.qualifier.rel
374
+ [basic.types]: #basic.types
375
+ [bit.cast]: numerics.md#bit.cast
376
+ [c.malloc]: utilities.md#c.malloc
377
+ [class]: class.md#class
378
+ [class.abstract]: class.md#class.abstract
379
+ [class.access]: class.md#class.access
380
+ [class.base.init]: class.md#class.base.init
381
+ [class.bit]: class.md#class.bit
382
+ [class.cdtor]: class.md#class.cdtor
383
+ [class.conv.fct]: class.md#class.conv.fct
384
+ [class.copy.assign]: class.md#class.copy.assign
385
+ [class.copy.ctor]: class.md#class.copy.ctor
386
+ [class.copy.elision]: class.md#class.copy.elision
387
+ [class.default.ctor]: class.md#class.default.ctor
388
+ [class.derived]: class.md#class.derived
389
+ [class.dtor]: class.md#class.dtor
390
+ [class.free]: class.md#class.free
391
+ [class.friend]: class.md#class.friend
392
+ [class.local]: class.md#class.local
393
+ [class.mem]: class.md#class.mem
394
+ [class.member.lookup]: class.md#class.member.lookup
395
+ [class.mfct]: class.md#class.mfct
396
+ [class.mfct.non-static]: class.md#class.mfct.non-static
397
+ [class.name]: class.md#class.name
398
+ [class.nest]: class.md#class.nest
399
+ [class.pre]: class.md#class.pre
400
+ [class.prop]: class.md#class.prop
401
+ [class.qual]: #class.qual
402
+ [class.spaceship]: class.md#class.spaceship
403
+ [class.static]: class.md#class.static
404
+ [class.static.data]: class.md#class.static.data
405
+ [class.temporary]: #class.temporary
406
+ [class.this]: class.md#class.this
407
+ [class.union]: class.md#class.union
408
+ [class.virtual]: class.md#class.virtual
409
+ [conv]: expr.md#conv
410
+ [conv.array]: expr.md#conv.array
411
+ [conv.func]: expr.md#conv.func
412
+ [conv.integral]: expr.md#conv.integral
413
+ [conv.lval]: expr.md#conv.lval
414
+ [conv.mem]: expr.md#conv.mem
415
+ [conv.prom]: expr.md#conv.prom
416
+ [conv.ptr]: expr.md#conv.ptr
417
+ [conv.rank]: #conv.rank
418
+ [conv.rval]: expr.md#conv.rval
419
+ [cpp.predefined]: cpp.md#cpp.predefined
420
+ [cstddef.syn]: support.md#cstddef.syn
421
+ [cstring.syn]: strings.md#cstring.syn
422
+ [dcl.align]: dcl.md#dcl.align
423
+ [dcl.array]: dcl.md#dcl.array
424
+ [dcl.attr]: dcl.md#dcl.attr
425
+ [dcl.attr.nouniqueaddr]: dcl.md#dcl.attr.nouniqueaddr
426
+ [dcl.constexpr]: dcl.md#dcl.constexpr
427
+ [dcl.dcl]: dcl.md#dcl.dcl
428
+ [dcl.decl]: dcl.md#dcl.decl
429
+ [dcl.enum]: dcl.md#dcl.enum
430
+ [dcl.fct]: dcl.md#dcl.fct
431
+ [dcl.fct.def]: dcl.md#dcl.fct.def
432
+ [dcl.fct.def.coroutine]: dcl.md#dcl.fct.def.coroutine
433
+ [dcl.fct.def.general]: dcl.md#dcl.fct.def.general
434
+ [dcl.fct.default]: dcl.md#dcl.fct.default
435
+ [dcl.init]: dcl.md#dcl.init
436
+ [dcl.init.aggr]: dcl.md#dcl.init.aggr
437
+ [dcl.init.list]: dcl.md#dcl.init.list
438
+ [dcl.init.ref]: dcl.md#dcl.init.ref
439
+ [dcl.inline]: dcl.md#dcl.inline
440
+ [dcl.link]: dcl.md#dcl.link
441
+ [dcl.meaning]: dcl.md#dcl.meaning
442
+ [dcl.mptr]: dcl.md#dcl.mptr
443
+ [dcl.name]: dcl.md#dcl.name
444
+ [dcl.pre]: dcl.md#dcl.pre
445
+ [dcl.ptr]: dcl.md#dcl.ptr
446
+ [dcl.ref]: dcl.md#dcl.ref
447
+ [dcl.spec]: dcl.md#dcl.spec
448
+ [dcl.spec.auto]: dcl.md#dcl.spec.auto
449
+ [dcl.stc]: dcl.md#dcl.stc
450
+ [dcl.struct.bind]: dcl.md#dcl.struct.bind
451
+ [dcl.type.elab]: dcl.md#dcl.type.elab
452
+ [dcl.typedef]: dcl.md#dcl.typedef
453
+ [defns.block]: intro.md#defns.block
454
+ [defns.signature]: intro.md#defns.signature
455
+ [defns.signature.templ]: intro.md#defns.signature.templ
456
+ [depr.local]: future.md#depr.local
457
+ [depr.static.constexpr]: future.md#depr.static.constexpr
458
+ [diff.cpp11.basic]: compatibility.md#diff.cpp11.basic
459
+ [enum.udecl]: dcl.md#enum.udecl
460
+ [except.handle]: except.md#except.handle
461
+ [except.pre]: except.md#except.pre
462
+ [except.spec]: except.md#except.spec
463
+ [except.terminate]: except.md#except.terminate
464
+ [except.throw]: except.md#except.throw
465
+ [expr]: expr.md#expr
466
+ [expr.add]: expr.md#expr.add
467
+ [expr.alignof]: expr.md#expr.alignof
468
+ [expr.arith.conv]: expr.md#expr.arith.conv
469
+ [expr.ass]: expr.md#expr.ass
470
+ [expr.await]: expr.md#expr.await
471
+ [expr.call]: expr.md#expr.call
472
+ [expr.cast]: expr.md#expr.cast
473
+ [expr.comma]: expr.md#expr.comma
474
+ [expr.compound]: expr.md#expr.compound
475
+ [expr.cond]: expr.md#expr.cond
476
+ [expr.const]: expr.md#expr.const
477
+ [expr.const.cast]: expr.md#expr.const.cast
478
+ [expr.context]: expr.md#expr.context
479
+ [expr.delete]: expr.md#expr.delete
480
+ [expr.dynamic.cast]: expr.md#expr.dynamic.cast
481
+ [expr.eq]: expr.md#expr.eq
482
+ [expr.log.and]: expr.md#expr.log.and
483
+ [expr.log.or]: expr.md#expr.log.or
484
+ [expr.mptr.oper]: expr.md#expr.mptr.oper
485
+ [expr.new]: expr.md#expr.new
486
+ [expr.pre]: expr.md#expr.pre
487
+ [expr.prim.id]: expr.md#expr.prim.id
488
+ [expr.prim.id.dtor]: expr.md#expr.prim.id.dtor
489
+ [expr.prim.id.qual]: expr.md#expr.prim.id.qual
490
+ [expr.prim.lambda]: expr.md#expr.prim.lambda
491
+ [expr.prim.lambda.capture]: expr.md#expr.prim.lambda.capture
492
+ [expr.prim.lambda.closure]: expr.md#expr.prim.lambda.closure
493
+ [expr.prim.this]: expr.md#expr.prim.this
494
+ [expr.prop]: expr.md#expr.prop
495
+ [expr.ref]: expr.md#expr.ref
496
+ [expr.reinterpret.cast]: expr.md#expr.reinterpret.cast
497
+ [expr.rel]: expr.md#expr.rel
498
+ [expr.sizeof]: expr.md#expr.sizeof
499
+ [expr.static.cast]: expr.md#expr.static.cast
500
+ [expr.sub]: expr.md#expr.sub
501
+ [expr.type.conv]: expr.md#expr.type.conv
502
+ [expr.typeid]: expr.md#expr.typeid
503
+ [expr.unary.op]: expr.md#expr.unary.op
504
+ [get.new.handler]: support.md#get.new.handler
505
+ [headers]: library.md#headers
506
+ [intro.execution]: #intro.execution
507
+ [intro.memory]: #intro.memory
508
+ [intro.multithread]: #intro.multithread
509
+ [intro.object]: #intro.object
510
+ [intro.progress]: #intro.progress
511
+ [intro.races]: #intro.races
512
+ [lex.charset]: lex.md#lex.charset
513
+ [lex.name]: lex.md#lex.name
514
+ [lex.separate]: lex.md#lex.separate
515
+ [locale]: localization.md#locale
516
+ [meta.trans.other]: utilities.md#meta.trans.other
517
+ [module.context]: module.md#module.context
518
+ [module.global.frag]: module.md#module.global.frag
519
+ [module.import]: module.md#module.import
520
+ [module.interface]: module.md#module.interface
521
+ [module.reach]: module.md#module.reach
522
+ [module.unit]: module.md#module.unit
523
+ [multibyte.strings]: library.md#multibyte.strings
524
+ [namespace.def]: dcl.md#namespace.def
525
+ [namespace.memdef]: dcl.md#namespace.memdef
526
+ [namespace.qual]: #namespace.qual
527
+ [namespace.udecl]: dcl.md#namespace.udecl
528
+ [namespace.udir]: dcl.md#namespace.udir
529
+ [new.delete]: support.md#new.delete
530
+ [new.delete.array]: support.md#new.delete.array
531
+ [new.delete.placement]: support.md#new.delete.placement
532
+ [new.delete.single]: support.md#new.delete.single
533
+ [new.handler]: support.md#new.handler
534
+ [over]: over.md#over
535
+ [over.literal]: over.md#over.literal
536
+ [over.match]: over.md#over.match
537
+ [over.oper]: over.md#over.oper
538
+ [over.over]: over.md#over.over
539
+ [ptr.align]: utilities.md#ptr.align
540
+ [ptr.launder]: support.md#ptr.launder
541
+ [replacement.functions]: library.md#replacement.functions
542
+ [special]: class.md#special
543
+ [stmt.block]: stmt.md#stmt.block
544
+ [stmt.dcl]: stmt.md#stmt.dcl
545
+ [stmt.expr]: stmt.md#stmt.expr
546
+ [stmt.goto]: stmt.md#stmt.goto
547
+ [stmt.if]: stmt.md#stmt.if
548
+ [stmt.label]: stmt.md#stmt.label
549
+ [stmt.ranged]: stmt.md#stmt.ranged
550
+ [stmt.return]: stmt.md#stmt.return
551
+ [support.dynamic]: support.md#support.dynamic
552
+ [support.limits]: support.md#support.limits
553
+ [support.runtime]: support.md#support.runtime
554
+ [support.start.term]: support.md#support.start.term
555
+ [support.types]: support.md#support.types
556
+ [temp.deduct.guide]: temp.md#temp.deduct.guide
557
+ [temp.dep]: temp.md#temp.dep
558
+ [temp.dep.candidate]: temp.md#temp.dep.candidate
559
+ [temp.expl.spec]: temp.md#temp.expl.spec
560
+ [temp.explicit]: temp.md#temp.explicit
561
+ [temp.local]: temp.md#temp.local
562
+ [temp.names]: temp.md#temp.names
563
+ [temp.nondep]: temp.md#temp.nondep
564
+ [temp.over]: temp.md#temp.over
565
+ [temp.param]: temp.md#temp.param
566
+ [temp.point]: temp.md#temp.point
567
+ [temp.pre]: temp.md#temp.pre
568
+ [temp.res]: temp.md#temp.res
569
+ [temp.spec]: temp.md#temp.spec
570
+ [temp.type]: temp.md#temp.type
571
+ [thread]: thread.md#thread
572
+ [thread.jthread.class]: thread.md#thread.jthread.class
573
+ [thread.thread.class]: thread.md#thread.thread.class
574
+ [thread.threads]: thread.md#thread.threads
575
+ [util.dynamic.safety]: utilities.md#util.dynamic.safety
576
+
577
+ [^1]: Appearing inside the brace-enclosed *declaration-seq* in a
578
+ *linkage-specification* does not affect whether a declaration is a
579
+ definition.
580
+
581
+ [^2]: An implementation is not required to call allocation and
582
+ deallocation functions from constructors or destructors; however,
583
+ this is a permissible implementation technique.
584
+
585
+ [^3]: This refers to unqualified names that occur, for instance, in a
586
+ type or default argument in the *parameter-declaration-clause* or
587
+ used in the function body.
588
+
589
+ [^4]: This refers to unqualified names following the class name; such a
590
+ name may be used in a *base-specifier* or in the
591
+ *member-specification* of the class definition.
592
+
593
+ [^5]: This lookup applies whether the definition of `X` is nested within
594
+ `Y`’s definition or whether `X`’s definition appears in a namespace
595
+ scope enclosing `Y`’s definition [[class.nest]].
596
+
597
+ [^6]: That is, an unqualified name that occurs, for instance, in a type
598
+ in the *parameter-declaration-clause* or in the
599
+ *noexcept-specifier*.
600
+
601
+ [^7]: This lookup applies whether the member function is defined within
602
+ the definition of class `X` or whether the member function is
603
+ defined in a namespace scope enclosing `X`’s definition.
604
+
605
+ [^8]: Lookups in which function names are ignored include names
606
+ appearing in a *nested-name-specifier*, an
607
+ *elaborated-type-specifier*, or a *base-specifier*.
608
+
609
+ [^9]: The number of bits in a byte is reported by the macro `CHAR_BIT`
610
+ in the header `<climits>`.
611
+
612
+ [^10]: Under the “as-if” rule an implementation is allowed to store two
613
+ objects at the same machine address or not store an object at all if
614
+ the program cannot observe the difference [[intro.execution]].
615
+
616
+ [^11]: For example, before the construction of a global object that is
617
+ initialized via a user-provided constructor [[class.cdtor]].
618
+
619
+ [^12]: That is, an object for which a destructor will be called
620
+ implicitly—upon exit from the block for an object with automatic
621
+ storage duration, upon exit from the thread for an object with
622
+ thread storage duration, or upon exit from the program for an object
623
+ with static storage duration.
624
+
625
+ [^13]: Some implementations might define that copying an invalid pointer
626
+ value causes a system-generated runtime fault.
627
+
628
+ [^14]: The intent is to have `operator new()` implementable by calling
629
+ `std::malloc()` or `std::calloc()`, so the rules are substantially
630
+ the same. C++ differs from C in requiring a zero request to return a
631
+ non-null pointer.
632
+
633
+ [^15]: The global `operator delete(void*, std::size_t)` precludes use of
634
+ an allocation function `void operator new(std::size_t, std::size_t)`
635
+ as a placement allocation function ([[diff.cpp11.basic]]).
636
+
637
+ [^16]: This subclause does not impose restrictions on indirection
638
+ through pointers to memory not allocated by `::operator new`. This
639
+ maintains the ability of many C++ implementations to use binary
640
+ libraries and components written in other languages. In particular,
641
+ this applies to C binaries, because indirection through pointers to
642
+ memory allocated by `std::malloc` is not restricted.
643
+
644
+ [^17]: The same rules apply to initialization of an `initializer_list`
645
+ object [[dcl.init.list]] with its underlying temporary array.
646
+
647
+ [^18]: By using, for example, the library functions [[headers]]
648
+ `std::memcpy` or `std::memmove`.
649
+
650
+ [^19]: By using, for example, the library functions [[headers]]
651
+ `std::memcpy` or `std::memmove`.
652
+
653
+ [^20]: The intent is that the memory model of C++ is compatible with
654
+ that of ISO/IEC 9899 Programming Language C.
655
+
656
+ [^21]: The size and layout of an instance of an incompletely-defined
657
+ object type is unknown.
658
+
659
+ [^22]: This is also known as two’s complement representation.
660
+
661
+ [^23]: Static class members are objects or functions, and pointers to
662
+ them are ordinary pointers to objects or functions.
663
+
664
+ [^24]: For an object that is not within its lifetime, this is the first
665
+ byte in memory that it will occupy or used to occupy.
666
+
667
+ [^25]: The same representation and alignment requirements are meant to
668
+ imply interchangeability as arguments to functions, return values
669
+ from functions, and non-static data members of unions.
670
+
671
+ [^26]: As specified in  [[class.temporary]], after a full-expression is
672
+ evaluated, a sequence of zero or more invocations of destructor
673
+ functions for temporary objects takes place, usually in reverse
674
+ order of the construction of each temporary object.
675
+
676
+ [^27]: In other words, function executions do not interleave with each
677
+ other.
678
+
679
+ [^28]: An object with automatic or thread storage duration [[basic.stc]]
680
+ is associated with one specific thread, and can be accessed by a
681
+ different thread only indirectly through a pointer or reference
682
+ [[basic.compound]].
683
+
684
+ [^29]: A non-local variable with static storage duration having
685
+ initialization with side effects is initialized in this case, even
686
+ if it is not itself odr-used ([[basic.def.odr]],
687
+ [[basic.stc.static]]).