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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Program execution <a id="basic.exec">[[basic.exec]]</a>
|
| 2 |
+
|
| 3 |
+
### Sequential execution <a id="intro.execution">[[intro.execution]]</a>
|
| 4 |
+
|
| 5 |
+
An instance of each object with automatic storage duration
|
| 6 |
+
[[basic.stc.auto]] is associated with each entry into its block. Such an
|
| 7 |
+
object exists and retains its last-stored value during the execution of
|
| 8 |
+
the block and while the block is suspended (by a call of a function,
|
| 9 |
+
suspension of a coroutine [[expr.await]], or receipt of a signal).
|
| 10 |
+
|
| 11 |
+
A *constituent expression* is defined as follows:
|
| 12 |
+
|
| 13 |
+
- The constituent expression of an expression is that expression.
|
| 14 |
+
- The constituent expressions of a *braced-init-list* or of a (possibly
|
| 15 |
+
parenthesized) *expression-list* are the constituent expressions of
|
| 16 |
+
the elements of the respective list.
|
| 17 |
+
- The constituent expressions of a *brace-or-equal-initializer* of the
|
| 18 |
+
form `=` *initializer-clause* are the constituent expressions of the
|
| 19 |
+
*initializer-clause*.
|
| 20 |
+
|
| 21 |
+
[*Example 1*:
|
| 22 |
+
|
| 23 |
+
``` cpp
|
| 24 |
+
struct A { int x; };
|
| 25 |
+
struct B { int y; struct A a; };
|
| 26 |
+
B b = { 5, { 1+1 } };
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
The constituent expressions of the *initializer* used for the
|
| 30 |
+
initialization of `b` are `5` and `1+1`.
|
| 31 |
+
|
| 32 |
+
— *end example*]
|
| 33 |
+
|
| 34 |
+
The *immediate subexpressions* of an expression E are
|
| 35 |
+
|
| 36 |
+
- the constituent expressions of E’s operands [[expr.prop]],
|
| 37 |
+
- any function call that E implicitly invokes,
|
| 38 |
+
- if E is a *lambda-expression* [[expr.prim.lambda]], the initialization
|
| 39 |
+
of the entities captured by copy and the constituent expressions of
|
| 40 |
+
the *initializer* of the *init-capture*s,
|
| 41 |
+
- if E is a function call [[expr.call]] or implicitly invokes a
|
| 42 |
+
function, the constituent expressions of each default argument
|
| 43 |
+
[[dcl.fct.default]] used in the call, or
|
| 44 |
+
- if E creates an aggregate object [[dcl.init.aggr]], the constituent
|
| 45 |
+
expressions of each default member initializer [[class.mem]] used in
|
| 46 |
+
the initialization.
|
| 47 |
+
|
| 48 |
+
A *subexpression* of an expression E is an immediate subexpression of E
|
| 49 |
+
or a subexpression of an immediate subexpression of E.
|
| 50 |
+
|
| 51 |
+
[*Note 1*: Expressions appearing in the *compound-statement* of a
|
| 52 |
+
*lambda-expression* are not subexpressions of the
|
| 53 |
+
*lambda-expression*. — *end note*]
|
| 54 |
+
|
| 55 |
+
A *full-expression* is
|
| 56 |
+
|
| 57 |
+
- an unevaluated operand [[expr.prop]],
|
| 58 |
+
- a *constant-expression* [[expr.const]],
|
| 59 |
+
- an immediate invocation [[expr.const]],
|
| 60 |
+
- an *init-declarator* [[dcl.decl]] or a *mem-initializer*
|
| 61 |
+
[[class.base.init]], including the constituent expressions of the
|
| 62 |
+
initializer,
|
| 63 |
+
- an invocation of a destructor generated at the end of the lifetime of
|
| 64 |
+
an object other than a temporary object [[class.temporary]] whose
|
| 65 |
+
lifetime has not been extended, or
|
| 66 |
+
- an expression that is not a subexpression of another expression and
|
| 67 |
+
that is not otherwise part of a full-expression.
|
| 68 |
+
|
| 69 |
+
If a language construct is defined to produce an implicit call of a
|
| 70 |
+
function, a use of the language construct is considered to be an
|
| 71 |
+
expression for the purposes of this definition. Conversions applied to
|
| 72 |
+
the result of an expression in order to satisfy the requirements of the
|
| 73 |
+
language construct in which the expression appears are also considered
|
| 74 |
+
to be part of the full-expression. For an initializer, performing the
|
| 75 |
+
initialization of the entity (including evaluating default member
|
| 76 |
+
initializers of an aggregate) is also considered part of the
|
| 77 |
+
full-expression.
|
| 78 |
+
|
| 79 |
+
[*Example 2*:
|
| 80 |
+
|
| 81 |
+
``` cpp
|
| 82 |
+
struct S {
|
| 83 |
+
S(int i): I(i) { } // full-expression is initialization of I
|
| 84 |
+
int& v() { return I; }
|
| 85 |
+
~S() noexcept(false) { }
|
| 86 |
+
private:
|
| 87 |
+
int I;
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
S s1(1); // full-expression comprises call of S::S(int)
|
| 91 |
+
void f() {
|
| 92 |
+
S s2 = 2; // full-expression comprises call of S::S(int)
|
| 93 |
+
if (S(3).v()) // full-expression includes lvalue-to-rvalue and int to bool conversions,
|
| 94 |
+
// performed before temporary is deleted at end of full-expression
|
| 95 |
+
{ }
|
| 96 |
+
bool b = noexcept(S()); // exception specification of destructor of S considered for noexcept
|
| 97 |
+
|
| 98 |
+
// full-expression is destruction of s2 at end of block
|
| 99 |
+
}
|
| 100 |
+
struct B {
|
| 101 |
+
B(S = S(0));
|
| 102 |
+
};
|
| 103 |
+
B b[2] = { B(), B() }; // full-expression is the entire initialization
|
| 104 |
+
// including the destruction of temporaries
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
— *end example*]
|
| 108 |
+
|
| 109 |
+
[*Note 2*: The evaluation of a full-expression can include the
|
| 110 |
+
evaluation of subexpressions that are not lexically part of the
|
| 111 |
+
full-expression. For example, subexpressions involved in evaluating
|
| 112 |
+
default arguments [[dcl.fct.default]] are considered to be created in
|
| 113 |
+
the expression that calls the function, not the expression that defines
|
| 114 |
+
the default argument. — *end note*]
|
| 115 |
+
|
| 116 |
+
Reading an object designated by a `volatile` glvalue [[basic.lval]],
|
| 117 |
+
modifying an object, calling a library I/O function, or calling a
|
| 118 |
+
function that does any of those operations are all *side effects*, which
|
| 119 |
+
are changes in the state of the execution environment. *Evaluation* of
|
| 120 |
+
an expression (or a subexpression) in general includes both value
|
| 121 |
+
computations (including determining the identity of an object for
|
| 122 |
+
glvalue evaluation and fetching a value previously assigned to an object
|
| 123 |
+
for prvalue evaluation) and initiation of side effects. When a call to a
|
| 124 |
+
library I/O function returns or an access through a volatile glvalue is
|
| 125 |
+
evaluated the side effect is considered complete, even though some
|
| 126 |
+
external actions implied by the call (such as the I/O itself) or by the
|
| 127 |
+
`volatile` access may not have completed yet.
|
| 128 |
+
|
| 129 |
+
*Sequenced before* is an asymmetric, transitive, pair-wise relation
|
| 130 |
+
between evaluations executed by a single thread [[intro.multithread]],
|
| 131 |
+
which induces a partial order among those evaluations. Given any two
|
| 132 |
+
evaluations *A* and *B*, if *A* is sequenced before *B* (or,
|
| 133 |
+
equivalently, *B* is *sequenced after* *A*), then the execution of *A*
|
| 134 |
+
shall precede the execution of *B*. If *A* is not sequenced before *B*
|
| 135 |
+
and *B* is not sequenced before *A*, then *A* and *B* are *unsequenced*.
|
| 136 |
+
|
| 137 |
+
[*Note 3*: The execution of unsequenced evaluations can
|
| 138 |
+
overlap. — *end note*]
|
| 139 |
+
|
| 140 |
+
Evaluations *A* and *B* are *indeterminately sequenced* when either *A*
|
| 141 |
+
is sequenced before *B* or *B* is sequenced before *A*, but it is
|
| 142 |
+
unspecified which.
|
| 143 |
+
|
| 144 |
+
[*Note 4*: Indeterminately sequenced evaluations cannot overlap, but
|
| 145 |
+
either could be executed first. — *end note*]
|
| 146 |
+
|
| 147 |
+
An expression *X* is said to be sequenced before an expression *Y* if
|
| 148 |
+
every value computation and every side effect associated with the
|
| 149 |
+
expression *X* is sequenced before every value computation and every
|
| 150 |
+
side effect associated with the expression *Y*.
|
| 151 |
+
|
| 152 |
+
Every value computation and side effect associated with a
|
| 153 |
+
full-expression is sequenced before every value computation and side
|
| 154 |
+
effect associated with the next full-expression to be evaluated.[^26]
|
| 155 |
+
|
| 156 |
+
Except where noted, evaluations of operands of individual operators and
|
| 157 |
+
of subexpressions of individual expressions are unsequenced.
|
| 158 |
+
|
| 159 |
+
[*Note 5*: In an expression that is evaluated more than once during the
|
| 160 |
+
execution of a program, unsequenced and indeterminately sequenced
|
| 161 |
+
evaluations of its subexpressions need not be performed consistently in
|
| 162 |
+
different evaluations. — *end note*]
|
| 163 |
+
|
| 164 |
+
The value computations of the operands of an operator are sequenced
|
| 165 |
+
before the value computation of the result of the operator. If a side
|
| 166 |
+
effect on a memory location [[intro.memory]] is unsequenced relative to
|
| 167 |
+
either another side effect on the same memory location or a value
|
| 168 |
+
computation using the value of any object in the same memory location,
|
| 169 |
+
and they are not potentially concurrent [[intro.multithread]], the
|
| 170 |
+
behavior is undefined.
|
| 171 |
+
|
| 172 |
+
[*Note 6*: The next subclause imposes similar, but more complex
|
| 173 |
+
restrictions on potentially concurrent computations. — *end note*]
|
| 174 |
+
|
| 175 |
+
[*Example 3*:
|
| 176 |
+
|
| 177 |
+
``` cpp
|
| 178 |
+
void g(int i) {
|
| 179 |
+
i = 7, i++, i++; // i becomes 9
|
| 180 |
+
|
| 181 |
+
i = i++ + 1; // the value of i is incremented
|
| 182 |
+
i = i++ + i; // undefined behavior
|
| 183 |
+
i = i + 1; // the value of i is incremented
|
| 184 |
+
}
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
— *end example*]
|
| 188 |
+
|
| 189 |
+
When calling a function (whether or not the function is inline), every
|
| 190 |
+
value computation and side effect associated with any argument
|
| 191 |
+
expression, or with the postfix expression designating the called
|
| 192 |
+
function, is sequenced before execution of every expression or statement
|
| 193 |
+
in the body of the called function. For each function invocation *F*,
|
| 194 |
+
for every evaluation *A* that occurs within *F* and every evaluation *B*
|
| 195 |
+
that does not occur within *F* but is evaluated on the same thread and
|
| 196 |
+
as part of the same signal handler (if any), either *A* is sequenced
|
| 197 |
+
before *B* or *B* is sequenced before *A*.[^27]
|
| 198 |
+
|
| 199 |
+
[*Note 7*: If *A* and *B* would not otherwise be sequenced then they
|
| 200 |
+
are indeterminately sequenced. — *end note*]
|
| 201 |
+
|
| 202 |
+
Several contexts in C++ cause evaluation of a function call, even though
|
| 203 |
+
no corresponding function call syntax appears in the translation unit.
|
| 204 |
+
|
| 205 |
+
[*Example 4*: Evaluation of a *new-expression* invokes one or more
|
| 206 |
+
allocation and constructor functions; see [[expr.new]]. For another
|
| 207 |
+
example, invocation of a conversion function [[class.conv.fct]] can
|
| 208 |
+
arise in contexts in which no function call syntax
|
| 209 |
+
appears. — *end example*]
|
| 210 |
+
|
| 211 |
+
The sequencing constraints on the execution of the called function (as
|
| 212 |
+
described above) are features of the function calls as evaluated,
|
| 213 |
+
whatever the syntax of the expression that calls the function might be.
|
| 214 |
+
|
| 215 |
+
If a signal handler is executed as a result of a call to the
|
| 216 |
+
`std::raise` function, then the execution of the handler is sequenced
|
| 217 |
+
after the invocation of the `std::raise` function and before its return.
|
| 218 |
+
|
| 219 |
+
[*Note 8*: When a signal is received for another reason, the execution
|
| 220 |
+
of the signal handler is usually unsequenced with respect to the rest of
|
| 221 |
+
the program. — *end note*]
|
| 222 |
+
|
| 223 |
+
### Multi-threaded executions and data races <a id="intro.multithread">[[intro.multithread]]</a>
|
| 224 |
+
|
| 225 |
+
A *thread of execution* (also known as a *thread*) is a single flow of
|
| 226 |
+
control within a program, including the initial invocation of a specific
|
| 227 |
+
top-level function, and recursively including every function invocation
|
| 228 |
+
subsequently executed by the thread.
|
| 229 |
+
|
| 230 |
+
[*Note 1*: When one thread creates another, the initial call to the
|
| 231 |
+
top-level function of the new thread is executed by the new thread, not
|
| 232 |
+
by the creating thread. — *end note*]
|
| 233 |
+
|
| 234 |
+
Every thread in a program can potentially access every object and
|
| 235 |
+
function in a program.[^28] Under a hosted implementation, a C++ program
|
| 236 |
+
can have more than one thread running concurrently. The execution of
|
| 237 |
+
each thread proceeds as defined by the remainder of this document. The
|
| 238 |
+
execution of the entire program consists of an execution of all of its
|
| 239 |
+
threads.
|
| 240 |
+
|
| 241 |
+
[*Note 2*: Usually the execution can be viewed as an interleaving of
|
| 242 |
+
all its threads. However, some kinds of atomic operations, for example,
|
| 243 |
+
allow executions inconsistent with a simple interleaving, as described
|
| 244 |
+
below. — *end note*]
|
| 245 |
+
|
| 246 |
+
Under a freestanding implementation, it is *implementation-defined*
|
| 247 |
+
whether a program can have more than one thread of execution.
|
| 248 |
+
|
| 249 |
+
For a signal handler that is not executed as a result of a call to the
|
| 250 |
+
`std::raise` function, it is unspecified which thread of execution
|
| 251 |
+
contains the signal handler invocation.
|
| 252 |
+
|
| 253 |
+
#### Data races <a id="intro.races">[[intro.races]]</a>
|
| 254 |
+
|
| 255 |
+
The value of an object visible to a thread T at a particular point is
|
| 256 |
+
the initial value of the object, a value assigned to the object by T, or
|
| 257 |
+
a value assigned to the object by another thread, according to the rules
|
| 258 |
+
below.
|
| 259 |
+
|
| 260 |
+
[*Note 1*: In some cases, there may instead be undefined behavior. Much
|
| 261 |
+
of this subclause is motivated by the desire to support atomic
|
| 262 |
+
operations with explicit and detailed visibility constraints. However,
|
| 263 |
+
it also implicitly supports a simpler view for more restricted
|
| 264 |
+
programs. — *end note*]
|
| 265 |
+
|
| 266 |
+
Two expression evaluations *conflict* if one of them modifies a memory
|
| 267 |
+
location [[intro.memory]] and the other one reads or modifies the same
|
| 268 |
+
memory location.
|
| 269 |
+
|
| 270 |
+
The library defines a number of atomic operations [[atomics]] and
|
| 271 |
+
operations on mutexes [[thread]] that are specially identified as
|
| 272 |
+
synchronization operations. These operations play a special role in
|
| 273 |
+
making assignments in one thread visible to another. A synchronization
|
| 274 |
+
operation on one or more memory locations is either a consume operation,
|
| 275 |
+
an acquire operation, a release operation, or both an acquire and
|
| 276 |
+
release operation. A synchronization operation without an associated
|
| 277 |
+
memory location is a fence and can be either an acquire fence, a release
|
| 278 |
+
fence, or both an acquire and release fence. In addition, there are
|
| 279 |
+
relaxed atomic operations, which are not synchronization operations, and
|
| 280 |
+
atomic read-modify-write operations, which have special characteristics.
|
| 281 |
+
|
| 282 |
+
[*Note 2*: For example, a call that acquires a mutex will perform an
|
| 283 |
+
acquire operation on the locations comprising the mutex.
|
| 284 |
+
Correspondingly, a call that releases the same mutex will perform a
|
| 285 |
+
release operation on those same locations. Informally, performing a
|
| 286 |
+
release operation on A forces prior side effects on other memory
|
| 287 |
+
locations to become visible to other threads that later perform a
|
| 288 |
+
consume or an acquire operation on A. “Relaxed” atomic operations are
|
| 289 |
+
not synchronization operations even though, like synchronization
|
| 290 |
+
operations, they cannot contribute to data races. — *end note*]
|
| 291 |
+
|
| 292 |
+
All modifications to a particular atomic object M occur in some
|
| 293 |
+
particular total order, called the *modification order* of M.
|
| 294 |
+
|
| 295 |
+
[*Note 3*: There is a separate order for each atomic object. There is
|
| 296 |
+
no requirement that these can be combined into a single total order for
|
| 297 |
+
all objects. In general this will be impossible since different threads
|
| 298 |
+
may observe modifications to different objects in inconsistent
|
| 299 |
+
orders. — *end note*]
|
| 300 |
+
|
| 301 |
+
A *release sequence* headed by a release operation A on an atomic object
|
| 302 |
+
M is a maximal contiguous sub-sequence of side effects in the
|
| 303 |
+
modification order of M, where the first operation is A, and every
|
| 304 |
+
subsequent operation is an atomic read-modify-write operation.
|
| 305 |
+
|
| 306 |
+
Certain library calls *synchronize with* other library calls performed
|
| 307 |
+
by another thread. For example, an atomic store-release synchronizes
|
| 308 |
+
with a load-acquire that takes its value from the store
|
| 309 |
+
[[atomics.order]].
|
| 310 |
+
|
| 311 |
+
[*Note 4*: Except in the specified cases, reading a later value does
|
| 312 |
+
not necessarily ensure visibility as described below. Such a requirement
|
| 313 |
+
would sometimes interfere with efficient implementation. — *end note*]
|
| 314 |
+
|
| 315 |
+
[*Note 5*: The specifications of the synchronization operations define
|
| 316 |
+
when one reads the value written by another. For atomic objects, the
|
| 317 |
+
definition is clear. All operations on a given mutex occur in a single
|
| 318 |
+
total order. Each mutex acquisition “reads the value written” by the
|
| 319 |
+
last mutex release. — *end note*]
|
| 320 |
+
|
| 321 |
+
An evaluation A *carries a dependency* to an evaluation B if
|
| 322 |
+
|
| 323 |
+
- the value of A is used as an operand of B, unless:
|
| 324 |
+
- B is an invocation of any specialization of `std::kill_dependency`
|
| 325 |
+
[[atomics.order]], or
|
| 326 |
+
- A is the left operand of a built-in logical (`&&`, see
|
| 327 |
+
[[expr.log.and]]) or logical (`||`, see [[expr.log.or]]) operator,
|
| 328 |
+
or
|
| 329 |
+
- A is the left operand of a conditional (`?:`, see [[expr.cond]])
|
| 330 |
+
operator, or
|
| 331 |
+
- A is the left operand of the built-in comma (`,`) operator
|
| 332 |
+
[[expr.comma]];
|
| 333 |
+
|
| 334 |
+
or
|
| 335 |
+
- A writes a scalar object or bit-field M, B reads the value written by
|
| 336 |
+
A from M, and A is sequenced before B, or
|
| 337 |
+
- for some evaluation X, A carries a dependency to X, and X carries a
|
| 338 |
+
dependency to B.
|
| 339 |
+
|
| 340 |
+
[*Note 6*: “Carries a dependency to” is a subset of “is sequenced
|
| 341 |
+
before”, and is similarly strictly intra-thread. — *end note*]
|
| 342 |
+
|
| 343 |
+
An evaluation A is *dependency-ordered before* an evaluation B if
|
| 344 |
+
|
| 345 |
+
- A performs a release operation on an atomic object M, and, in another
|
| 346 |
+
thread, B performs a consume operation on M and reads the value
|
| 347 |
+
written by A, or
|
| 348 |
+
- for some evaluation X, A is dependency-ordered before X and X carries
|
| 349 |
+
a dependency to B.
|
| 350 |
+
|
| 351 |
+
[*Note 7*: The relation “is dependency-ordered before” is analogous to
|
| 352 |
+
“synchronizes with”, but uses release/consume in place of
|
| 353 |
+
release/acquire. — *end note*]
|
| 354 |
+
|
| 355 |
+
An evaluation A *inter-thread happens before* an evaluation B if
|
| 356 |
+
|
| 357 |
+
- A synchronizes with B, or
|
| 358 |
+
- A is dependency-ordered before B, or
|
| 359 |
+
- for some evaluation X
|
| 360 |
+
- A synchronizes with X and X is sequenced before B, or
|
| 361 |
+
- A is sequenced before X and X inter-thread happens before B, or
|
| 362 |
+
- A inter-thread happens before X and X inter-thread happens before B.
|
| 363 |
+
|
| 364 |
+
[*Note 8*: The “inter-thread happens before” relation describes
|
| 365 |
+
arbitrary concatenations of “sequenced before”, “synchronizes with” and
|
| 366 |
+
“dependency-ordered before” relationships, with two exceptions. The
|
| 367 |
+
first exception is that a concatenation is not permitted to end with
|
| 368 |
+
“dependency-ordered before” followed by “sequenced before”. The reason
|
| 369 |
+
for this limitation is that a consume operation participating in a
|
| 370 |
+
“dependency-ordered before” relationship provides ordering only with
|
| 371 |
+
respect to operations to which this consume operation actually carries a
|
| 372 |
+
dependency. The reason that this limitation applies only to the end of
|
| 373 |
+
such a concatenation is that any subsequent release operation will
|
| 374 |
+
provide the required ordering for a prior consume operation. The second
|
| 375 |
+
exception is that a concatenation is not permitted to consist entirely
|
| 376 |
+
of “sequenced before”. The reasons for this limitation are (1) to permit
|
| 377 |
+
“inter-thread happens before” to be transitively closed and (2) the
|
| 378 |
+
“happens before” relation, defined below, provides for relationships
|
| 379 |
+
consisting entirely of “sequenced before”. — *end note*]
|
| 380 |
+
|
| 381 |
+
An evaluation A *happens before* an evaluation B (or, equivalently, B
|
| 382 |
+
*happens after* A) if:
|
| 383 |
+
|
| 384 |
+
- A is sequenced before B, or
|
| 385 |
+
- A inter-thread happens before B.
|
| 386 |
+
|
| 387 |
+
The implementation shall ensure that no program execution demonstrates a
|
| 388 |
+
cycle in the “happens before” relation.
|
| 389 |
+
|
| 390 |
+
[*Note 9*: This cycle would otherwise be possible only through the use
|
| 391 |
+
of consume operations. — *end note*]
|
| 392 |
+
|
| 393 |
+
An evaluation A *simply happens before* an evaluation B if either
|
| 394 |
+
|
| 395 |
+
- A is sequenced before B, or
|
| 396 |
+
- A synchronizes with B, or
|
| 397 |
+
- A simply happens before X and X simply happens before B.
|
| 398 |
+
|
| 399 |
+
[*Note 10*: In the absence of consume operations, the happens before
|
| 400 |
+
and simply happens before relations are identical. — *end note*]
|
| 401 |
+
|
| 402 |
+
An evaluation A *strongly happens before* an evaluation D if, either
|
| 403 |
+
|
| 404 |
+
- A is sequenced before D, or
|
| 405 |
+
- A synchronizes with D, and both A and D are sequentially consistent
|
| 406 |
+
atomic operations [[atomics.order]], or
|
| 407 |
+
- there are evaluations B and C such that A is sequenced before B, B
|
| 408 |
+
simply happens before C, and C is sequenced before D, or
|
| 409 |
+
- there is an evaluation B such that A strongly happens before B, and B
|
| 410 |
+
strongly happens before D.
|
| 411 |
+
|
| 412 |
+
[*Note 11*: Informally, if A strongly happens before B, then A appears
|
| 413 |
+
to be evaluated before B in all contexts. Strongly happens before
|
| 414 |
+
excludes consume operations. — *end note*]
|
| 415 |
+
|
| 416 |
+
A *visible side effect* A on a scalar object or bit-field M with respect
|
| 417 |
+
to a value computation B of M satisfies the conditions:
|
| 418 |
+
|
| 419 |
+
- A happens before B and
|
| 420 |
+
- there is no other side effect X to M such that A happens before X and
|
| 421 |
+
X happens before B.
|
| 422 |
+
|
| 423 |
+
The value of a non-atomic scalar object or bit-field M, as determined by
|
| 424 |
+
evaluation B, shall be the value stored by the visible side effect A.
|
| 425 |
+
|
| 426 |
+
[*Note 12*: If there is ambiguity about which side effect to a
|
| 427 |
+
non-atomic object or bit-field is visible, then the behavior is either
|
| 428 |
+
unspecified or undefined. — *end note*]
|
| 429 |
+
|
| 430 |
+
[*Note 13*: This states that operations on ordinary objects are not
|
| 431 |
+
visibly reordered. This is not actually detectable without data races,
|
| 432 |
+
but it is necessary to ensure that data races, as defined below, and
|
| 433 |
+
with suitable restrictions on the use of atomics, correspond to data
|
| 434 |
+
races in a simple interleaved (sequentially consistent)
|
| 435 |
+
execution. — *end note*]
|
| 436 |
+
|
| 437 |
+
The value of an atomic object M, as determined by evaluation B, shall be
|
| 438 |
+
the value stored by some side effect A that modifies M, where B does not
|
| 439 |
+
happen before A.
|
| 440 |
+
|
| 441 |
+
[*Note 14*: The set of such side effects is also restricted by the rest
|
| 442 |
+
of the rules described here, and in particular, by the coherence
|
| 443 |
+
requirements below. — *end note*]
|
| 444 |
+
|
| 445 |
+
If an operation A that modifies an atomic object M happens before an
|
| 446 |
+
operation B that modifies M, then A shall be earlier than B in the
|
| 447 |
+
modification order of M.
|
| 448 |
+
|
| 449 |
+
[*Note 15*: This requirement is known as write-write
|
| 450 |
+
coherence. — *end note*]
|
| 451 |
+
|
| 452 |
+
If a value computation A of an atomic object M happens before a value
|
| 453 |
+
computation B of M, and A takes its value from a side effect X on M,
|
| 454 |
+
then the value computed by B shall either be the value stored by X or
|
| 455 |
+
the value stored by a side effect Y on M, where Y follows X in the
|
| 456 |
+
modification order of M.
|
| 457 |
+
|
| 458 |
+
[*Note 16*: This requirement is known as read-read
|
| 459 |
+
coherence. — *end note*]
|
| 460 |
+
|
| 461 |
+
If a value computation A of an atomic object M happens before an
|
| 462 |
+
operation B that modifies M, then A shall take its value from a side
|
| 463 |
+
effect X on M, where X precedes B in the modification order of M.
|
| 464 |
+
|
| 465 |
+
[*Note 17*: This requirement is known as read-write
|
| 466 |
+
coherence. — *end note*]
|
| 467 |
+
|
| 468 |
+
If a side effect X on an atomic object M happens before a value
|
| 469 |
+
computation B of M, then the evaluation B shall take its value from X or
|
| 470 |
+
from a side effect Y that follows X in the modification order of M.
|
| 471 |
+
|
| 472 |
+
[*Note 18*: This requirement is known as write-read
|
| 473 |
+
coherence. — *end note*]
|
| 474 |
+
|
| 475 |
+
[*Note 19*: The four preceding coherence requirements effectively
|
| 476 |
+
disallow compiler reordering of atomic operations to a single object,
|
| 477 |
+
even if both operations are relaxed loads. This effectively makes the
|
| 478 |
+
cache coherence guarantee provided by most hardware available to C++
|
| 479 |
+
atomic operations. — *end note*]
|
| 480 |
+
|
| 481 |
+
[*Note 20*: The value observed by a load of an atomic depends on the
|
| 482 |
+
“happens before” relation, which depends on the values observed by loads
|
| 483 |
+
of atomics. The intended reading is that there must exist an association
|
| 484 |
+
of atomic loads with modifications they observe that, together with
|
| 485 |
+
suitably chosen modification orders and the “happens before” relation
|
| 486 |
+
derived as described above, satisfy the resulting constraints as imposed
|
| 487 |
+
here. — *end note*]
|
| 488 |
+
|
| 489 |
+
Two actions are *potentially concurrent* if
|
| 490 |
+
|
| 491 |
+
- they are performed by different threads, or
|
| 492 |
+
- they are unsequenced, at least one is performed by a signal handler,
|
| 493 |
+
and they are not both performed by the same signal handler invocation.
|
| 494 |
+
|
| 495 |
+
The execution of a program contains a *data race* if it contains two
|
| 496 |
+
potentially concurrent conflicting actions, at least one of which is not
|
| 497 |
+
atomic, and neither happens before the other, except for the special
|
| 498 |
+
case for signal handlers described below. Any such data race results in
|
| 499 |
+
undefined behavior.
|
| 500 |
+
|
| 501 |
+
[*Note 21*: It can be shown that programs that correctly use mutexes
|
| 502 |
+
and `memory_order::seq_cst` operations to prevent all data races and use
|
| 503 |
+
no other synchronization operations behave as if the operations executed
|
| 504 |
+
by their constituent threads were simply interleaved, with each value
|
| 505 |
+
computation of an object being taken from the last side effect on that
|
| 506 |
+
object in that interleaving. This is normally referred to as “sequential
|
| 507 |
+
consistency”. However, this applies only to data-race-free programs, and
|
| 508 |
+
data-race-free programs cannot observe most program transformations that
|
| 509 |
+
do not change single-threaded program semantics. In fact, most
|
| 510 |
+
single-threaded program transformations continue to be allowed, since
|
| 511 |
+
any program that behaves differently as a result must perform an
|
| 512 |
+
undefined operation. — *end note*]
|
| 513 |
+
|
| 514 |
+
Two accesses to the same object of type `volatile std::sig_atomic_t` do
|
| 515 |
+
not result in a data race if both occur in the same thread, even if one
|
| 516 |
+
or more occurs in a signal handler. For each signal handler invocation,
|
| 517 |
+
evaluations performed by the thread invoking a signal handler can be
|
| 518 |
+
divided into two groups A and B, such that no evaluations in B happen
|
| 519 |
+
before evaluations in A, and the evaluations of such
|
| 520 |
+
`volatile std::sig_atomic_t` objects take values as though all
|
| 521 |
+
evaluations in A happened before the execution of the signal handler and
|
| 522 |
+
the execution of the signal handler happened before all evaluations in
|
| 523 |
+
B.
|
| 524 |
+
|
| 525 |
+
[*Note 22*: Compiler transformations that introduce assignments to a
|
| 526 |
+
potentially shared memory location that would not be modified by the
|
| 527 |
+
abstract machine are generally precluded by this document, since such an
|
| 528 |
+
assignment might overwrite another assignment by a different thread in
|
| 529 |
+
cases in which an abstract machine execution would not have encountered
|
| 530 |
+
a data race. This includes implementations of data member assignment
|
| 531 |
+
that overwrite adjacent members in separate memory locations. Reordering
|
| 532 |
+
of atomic loads in cases in which the atomics in question may alias is
|
| 533 |
+
also generally precluded, since this may violate the coherence
|
| 534 |
+
rules. — *end note*]
|
| 535 |
+
|
| 536 |
+
[*Note 23*: Transformations that introduce a speculative read of a
|
| 537 |
+
potentially shared memory location may not preserve the semantics of the
|
| 538 |
+
C++ program as defined in this document, since they potentially
|
| 539 |
+
introduce a data race. However, they are typically valid in the context
|
| 540 |
+
of an optimizing compiler that targets a specific machine with
|
| 541 |
+
well-defined semantics for data races. They would be invalid for a
|
| 542 |
+
hypothetical machine that is not tolerant of races or provides hardware
|
| 543 |
+
race detection. — *end note*]
|
| 544 |
+
|
| 545 |
+
#### Forward progress <a id="intro.progress">[[intro.progress]]</a>
|
| 546 |
+
|
| 547 |
+
The implementation may assume that any thread will eventually do one of
|
| 548 |
+
the following:
|
| 549 |
+
|
| 550 |
+
- terminate,
|
| 551 |
+
- make a call to a library I/O function,
|
| 552 |
+
- perform an access through a volatile glvalue, or
|
| 553 |
+
- perform a synchronization operation or an atomic operation.
|
| 554 |
+
|
| 555 |
+
[*Note 1*: This is intended to allow compiler transformations such as
|
| 556 |
+
removal of empty loops, even when termination cannot be
|
| 557 |
+
proven. — *end note*]
|
| 558 |
+
|
| 559 |
+
Executions of atomic functions that are either defined to be lock-free
|
| 560 |
+
[[atomics.flag]] or indicated as lock-free [[atomics.lockfree]] are
|
| 561 |
+
*lock-free executions*.
|
| 562 |
+
|
| 563 |
+
- If there is only one thread that is not blocked [[defns.block]] in a
|
| 564 |
+
standard library function, a lock-free execution in that thread shall
|
| 565 |
+
complete. \[*Note 2*: Concurrently executing threads may prevent
|
| 566 |
+
progress of a lock-free execution. For example, this situation can
|
| 567 |
+
occur with load-locked store-conditional implementations. This
|
| 568 |
+
property is sometimes termed obstruction-free. — *end note*]
|
| 569 |
+
- When one or more lock-free executions run concurrently, at least one
|
| 570 |
+
should complete. \[*Note 3*: It is difficult for some implementations
|
| 571 |
+
to provide absolute guarantees to this effect, since repeated and
|
| 572 |
+
particularly inopportune interference from other threads may prevent
|
| 573 |
+
forward progress, e.g., by repeatedly stealing a cache line for
|
| 574 |
+
unrelated purposes between load-locked and store-conditional
|
| 575 |
+
instructions. Implementations should ensure that such effects cannot
|
| 576 |
+
indefinitely delay progress under expected operating conditions, and
|
| 577 |
+
that such anomalies can therefore safely be ignored by programmers.
|
| 578 |
+
Outside this document, this property is sometimes termed
|
| 579 |
+
lock-free. — *end note*]
|
| 580 |
+
|
| 581 |
+
During the execution of a thread of execution, each of the following is
|
| 582 |
+
termed an *execution step*:
|
| 583 |
+
|
| 584 |
+
- termination of the thread of execution,
|
| 585 |
+
- performing an access through a volatile glvalue, or
|
| 586 |
+
- completion of a call to a library I/O function, a synchronization
|
| 587 |
+
operation, or an atomic operation.
|
| 588 |
+
|
| 589 |
+
An invocation of a standard library function that blocks [[defns.block]]
|
| 590 |
+
is considered to continuously execute execution steps while waiting for
|
| 591 |
+
the condition that it blocks on to be satisfied.
|
| 592 |
+
|
| 593 |
+
[*Example 1*: A library I/O function that blocks until the I/O
|
| 594 |
+
operation is complete can be considered to continuously check whether
|
| 595 |
+
the operation is complete. Each such check might consist of one or more
|
| 596 |
+
execution steps, for example using observable behavior of the abstract
|
| 597 |
+
machine. — *end example*]
|
| 598 |
+
|
| 599 |
+
[*Note 4*: Because of this and the preceding requirement regarding what
|
| 600 |
+
threads of execution have to perform eventually, it follows that no
|
| 601 |
+
thread of execution can execute forever without an execution step
|
| 602 |
+
occurring. — *end note*]
|
| 603 |
+
|
| 604 |
+
A thread of execution *makes progress* when an execution step occurs or
|
| 605 |
+
a lock-free execution does not complete because there are other
|
| 606 |
+
concurrent threads that are not blocked in a standard library function
|
| 607 |
+
(see above).
|
| 608 |
+
|
| 609 |
+
For a thread of execution providing *concurrent forward progress
|
| 610 |
+
guarantees*, the implementation ensures that the thread will eventually
|
| 611 |
+
make progress for as long as it has not terminated.
|
| 612 |
+
|
| 613 |
+
[*Note 5*: This is required regardless of whether or not other threads
|
| 614 |
+
of executions (if any) have been or are making progress. To eventually
|
| 615 |
+
fulfill this requirement means that this will happen in an unspecified
|
| 616 |
+
but finite amount of time. — *end note*]
|
| 617 |
+
|
| 618 |
+
It is *implementation-defined* whether the implementation-created thread
|
| 619 |
+
of execution that executes `main` [[basic.start.main]] and the threads
|
| 620 |
+
of execution created by `std::thread` [[thread.thread.class]] or
|
| 621 |
+
`std::jthread` [[thread.jthread.class]] provide concurrent forward
|
| 622 |
+
progress guarantees.
|
| 623 |
+
|
| 624 |
+
[*Note 6*: General-purpose implementations should provide these
|
| 625 |
+
guarantees. — *end note*]
|
| 626 |
+
|
| 627 |
+
For a thread of execution providing *parallel forward progress
|
| 628 |
+
guarantees*, the implementation is not required to ensure that the
|
| 629 |
+
thread will eventually make progress if it has not yet executed any
|
| 630 |
+
execution step; once this thread has executed a step, it provides
|
| 631 |
+
concurrent forward progress guarantees.
|
| 632 |
+
|
| 633 |
+
[*Note 7*: This does not specify a requirement for when to start this
|
| 634 |
+
thread of execution, which will typically be specified by the entity
|
| 635 |
+
that creates this thread of execution. For example, a thread of
|
| 636 |
+
execution that provides concurrent forward progress guarantees and
|
| 637 |
+
executes tasks from a set of tasks in an arbitrary order, one after the
|
| 638 |
+
other, satisfies the requirements of parallel forward progress for these
|
| 639 |
+
tasks. — *end note*]
|
| 640 |
+
|
| 641 |
+
For a thread of execution providing *weakly parallel forward progress
|
| 642 |
+
guarantees*, the implementation does not ensure that the thread will
|
| 643 |
+
eventually make progress.
|
| 644 |
+
|
| 645 |
+
[*Note 8*: Threads of execution providing weakly parallel forward
|
| 646 |
+
progress guarantees cannot be expected to make progress regardless of
|
| 647 |
+
whether other threads make progress or not; however, blocking with
|
| 648 |
+
forward progress guarantee delegation, as defined below, can be used to
|
| 649 |
+
ensure that such threads of execution make progress
|
| 650 |
+
eventually. — *end note*]
|
| 651 |
+
|
| 652 |
+
Concurrent forward progress guarantees are stronger than parallel
|
| 653 |
+
forward progress guarantees, which in turn are stronger than weakly
|
| 654 |
+
parallel forward progress guarantees.
|
| 655 |
+
|
| 656 |
+
[*Note 9*: For example, some kinds of synchronization between threads
|
| 657 |
+
of execution may only make progress if the respective threads of
|
| 658 |
+
execution provide parallel forward progress guarantees, but will fail to
|
| 659 |
+
make progress under weakly parallel guarantees. — *end note*]
|
| 660 |
+
|
| 661 |
+
When a thread of execution P is specified to *block with forward
|
| 662 |
+
progress guarantee delegation* on the completion of a set S of threads
|
| 663 |
+
of execution, then throughout the whole time of P being blocked on S,
|
| 664 |
+
the implementation shall ensure that the forward progress guarantees
|
| 665 |
+
provided by at least one thread of execution in S is at least as strong
|
| 666 |
+
as P’s forward progress guarantees.
|
| 667 |
+
|
| 668 |
+
[*Note 10*: It is unspecified which thread or threads of execution in S
|
| 669 |
+
are chosen and for which number of execution steps. The strengthening is
|
| 670 |
+
not permanent and not necessarily in place for the rest of the lifetime
|
| 671 |
+
of the affected thread of execution. As long as P is blocked, the
|
| 672 |
+
implementation has to eventually select and potentially strengthen a
|
| 673 |
+
thread of execution in S. — *end note*]
|
| 674 |
+
|
| 675 |
+
Once a thread of execution in S terminates, it is removed from S. Once S
|
| 676 |
+
is empty, P is unblocked.
|
| 677 |
+
|
| 678 |
+
[*Note 11*: A thread of execution B thus can temporarily provide an
|
| 679 |
+
effectively stronger forward progress guarantee for a certain amount of
|
| 680 |
+
time, due to a second thread of execution A being blocked on it with
|
| 681 |
+
forward progress guarantee delegation. In turn, if B then blocks with
|
| 682 |
+
forward progress guarantee delegation on C, this may also temporarily
|
| 683 |
+
provide a stronger forward progress guarantee to C. — *end note*]
|
| 684 |
+
|
| 685 |
+
[*Note 12*: If all threads of execution in S finish executing (e.g.,
|
| 686 |
+
they terminate and do not use blocking synchronization incorrectly),
|
| 687 |
+
then P’s execution of the operation that blocks with forward progress
|
| 688 |
+
guarantee delegation will not result in P’s progress guarantee being
|
| 689 |
+
effectively weakened. — *end note*]
|
| 690 |
+
|
| 691 |
+
[*Note 13*: This does not remove any constraints regarding blocking
|
| 692 |
+
synchronization for threads of execution providing parallel or weakly
|
| 693 |
+
parallel forward progress guarantees because the implementation is not
|
| 694 |
+
required to strengthen a particular thread of execution whose too-weak
|
| 695 |
+
progress guarantee is preventing overall progress. — *end note*]
|
| 696 |
+
|
| 697 |
+
An implementation should ensure that the last value (in modification
|
| 698 |
+
order) assigned by an atomic or synchronization operation will become
|
| 699 |
+
visible to all other threads in a finite period of time.
|
| 700 |
+
|
| 701 |
+
### Start and termination <a id="basic.start">[[basic.start]]</a>
|
| 702 |
+
|
| 703 |
+
#### `main` function <a id="basic.start.main">[[basic.start.main]]</a>
|
| 704 |
+
|
| 705 |
+
A program shall contain a global function called `main` attached to the
|
| 706 |
+
global module. Executing a program starts a main thread of execution (
|
| 707 |
+
[[intro.multithread]], [[thread.threads]]) in which the `main` function
|
| 708 |
+
is invoked, and in which variables of static storage duration might be
|
| 709 |
+
initialized [[basic.start.static]] and destroyed [[basic.start.term]].
|
| 710 |
+
It is *implementation-defined* whether a program in a freestanding
|
| 711 |
+
environment is required to define a `main` function.
|
| 712 |
+
|
| 713 |
+
[*Note 1*: In a freestanding environment, startup and termination is
|
| 714 |
+
*implementation-defined*; startup contains the execution of constructors
|
| 715 |
+
for objects of namespace scope with static storage duration; termination
|
| 716 |
+
contains the execution of destructors for objects with static storage
|
| 717 |
+
duration. — *end note*]
|
| 718 |
+
|
| 719 |
+
An implementation shall not predefine the `main` function. This function
|
| 720 |
+
shall not be overloaded. Its type shall have C++ language linkage and it
|
| 721 |
+
shall have a declared return type of type `int`, but otherwise its type
|
| 722 |
+
is *implementation-defined*. An implementation shall allow both
|
| 723 |
+
|
| 724 |
+
- a function of `()` returning `int` and
|
| 725 |
+
- a function of `(int`, pointer to pointer to `char)` returning `int`
|
| 726 |
+
|
| 727 |
+
as the type of `main` [[dcl.fct]]. In the latter form, for purposes of
|
| 728 |
+
exposition, the first function parameter is called `argc` and the second
|
| 729 |
+
function parameter is called `argv`, where `argc` shall be the number of
|
| 730 |
+
arguments passed to the program from the environment in which the
|
| 731 |
+
program is run. If `argc` is nonzero these arguments shall be supplied
|
| 732 |
+
in `argv[0]` through `argv[argc-1]` as pointers to the initial
|
| 733 |
+
characters of null-terminated multibyte strings (NTMBSs)
|
| 734 |
+
[[multibyte.strings]] and `argv[0]` shall be the pointer to the initial
|
| 735 |
+
character of a NTMBS that represents the name used to invoke the program
|
| 736 |
+
or `""`. The value of `argc` shall be non-negative. The value of
|
| 737 |
+
`argv[argc]` shall be 0.
|
| 738 |
+
|
| 739 |
+
[*Note 2*: It is recommended that any further (optional) parameters be
|
| 740 |
+
added after `argv`. — *end note*]
|
| 741 |
+
|
| 742 |
+
The function `main` shall not be used within a program. The linkage
|
| 743 |
+
[[basic.link]] of `main` is *implementation-defined*. A program that
|
| 744 |
+
defines `main` as deleted or that declares `main` to be `inline`,
|
| 745 |
+
`static`, or `constexpr` is ill-formed. The function `main` shall not be
|
| 746 |
+
a coroutine [[dcl.fct.def.coroutine]]. The `main` function shall not be
|
| 747 |
+
declared with a *linkage-specification* [[dcl.link]]. A program that
|
| 748 |
+
declares a variable `main` at global scope, or that declares a function
|
| 749 |
+
`main` at global scope attached to a named module, or that declares the
|
| 750 |
+
name `main` with C language linkage (in any namespace) is ill-formed.
|
| 751 |
+
The name `main` is not otherwise reserved.
|
| 752 |
+
|
| 753 |
+
[*Example 1*: Member functions, classes, and enumerations can be called
|
| 754 |
+
`main`, as can entities in other namespaces. — *end example*]
|
| 755 |
+
|
| 756 |
+
Terminating the program without leaving the current block (e.g., by
|
| 757 |
+
calling the function `std::exit(int)` [[support.start.term]]) does not
|
| 758 |
+
destroy any objects with automatic storage duration [[class.dtor]]. If
|
| 759 |
+
`std::exit` is called to end a program during the destruction of an
|
| 760 |
+
object with static or thread storage duration, the program has undefined
|
| 761 |
+
behavior.
|
| 762 |
+
|
| 763 |
+
A `return` statement [[stmt.return]] in `main` has the effect of leaving
|
| 764 |
+
the main function (destroying any objects with automatic storage
|
| 765 |
+
duration) and calling `std::exit` with the return value as the argument.
|
| 766 |
+
If control flows off the end of the *compound-statement* of `main`, the
|
| 767 |
+
effect is equivalent to a `return` with operand `0` (see also
|
| 768 |
+
[[except.handle]]).
|
| 769 |
+
|
| 770 |
+
#### Static initialization <a id="basic.start.static">[[basic.start.static]]</a>
|
| 771 |
+
|
| 772 |
+
Variables with static storage duration are initialized as a consequence
|
| 773 |
+
of program initiation. Variables with thread storage duration are
|
| 774 |
+
initialized as a consequence of thread execution. Within each of these
|
| 775 |
+
phases of initiation, initialization occurs as follows.
|
| 776 |
+
|
| 777 |
+
*Constant initialization* is performed if a variable or temporary object
|
| 778 |
+
with static or thread storage duration is constant-initialized
|
| 779 |
+
[[expr.const]]. If constant initialization is not performed, a variable
|
| 780 |
+
with static storage duration [[basic.stc.static]] or thread storage
|
| 781 |
+
duration [[basic.stc.thread]] is zero-initialized [[dcl.init]].
|
| 782 |
+
Together, zero-initialization and constant initialization are called
|
| 783 |
+
*static initialization*; all other initialization is *dynamic
|
| 784 |
+
initialization*. All static initialization strongly happens before
|
| 785 |
+
[[intro.races]] any dynamic initialization.
|
| 786 |
+
|
| 787 |
+
[*Note 1*: The dynamic initialization of non-local variables is
|
| 788 |
+
described in [[basic.start.dynamic]]; that of local static variables is
|
| 789 |
+
described in [[stmt.dcl]]. — *end note*]
|
| 790 |
+
|
| 791 |
+
An implementation is permitted to perform the initialization of a
|
| 792 |
+
variable with static or thread storage duration as a static
|
| 793 |
+
initialization even if such initialization is not required to be done
|
| 794 |
+
statically, provided that
|
| 795 |
+
|
| 796 |
+
- the dynamic version of the initialization does not change the value of
|
| 797 |
+
any other object of static or thread storage duration prior to its
|
| 798 |
+
initialization, and
|
| 799 |
+
- the static version of the initialization produces the same value in
|
| 800 |
+
the initialized variable as would be produced by the dynamic
|
| 801 |
+
initialization if all variables not required to be initialized
|
| 802 |
+
statically were initialized dynamically.
|
| 803 |
+
|
| 804 |
+
[*Note 2*:
|
| 805 |
+
|
| 806 |
+
As a consequence, if the initialization of an object `obj1` refers to an
|
| 807 |
+
object `obj2` of namespace scope potentially requiring dynamic
|
| 808 |
+
initialization and defined later in the same translation unit, it is
|
| 809 |
+
unspecified whether the value of `obj2` used will be the value of the
|
| 810 |
+
fully initialized `obj2` (because `obj2` was statically initialized) or
|
| 811 |
+
will be the value of `obj2` merely zero-initialized. For example,
|
| 812 |
+
|
| 813 |
+
``` cpp
|
| 814 |
+
inline double fd() { return 1.0; }
|
| 815 |
+
extern double d1;
|
| 816 |
+
double d2 = d1; // unspecified:
|
| 817 |
+
// may be statically initialized to 0.0 or
|
| 818 |
+
// dynamically initialized to 0.0 if d1 is
|
| 819 |
+
// dynamically initialized, or 1.0 otherwise
|
| 820 |
+
double d1 = fd(); // may be initialized statically or dynamically to 1.0
|
| 821 |
+
```
|
| 822 |
+
|
| 823 |
+
— *end note*]
|
| 824 |
+
|
| 825 |
+
#### Dynamic initialization of non-local variables <a id="basic.start.dynamic">[[basic.start.dynamic]]</a>
|
| 826 |
+
|
| 827 |
+
Dynamic initialization of a non-local variable with static storage
|
| 828 |
+
duration is unordered if the variable is an implicitly or explicitly
|
| 829 |
+
instantiated specialization, is partially-ordered if the variable is an
|
| 830 |
+
inline variable that is not an implicitly or explicitly instantiated
|
| 831 |
+
specialization, and otherwise is ordered.
|
| 832 |
+
|
| 833 |
+
[*Note 1*: An explicitly specialized non-inline static data member or
|
| 834 |
+
variable template specialization has ordered
|
| 835 |
+
initialization. — *end note*]
|
| 836 |
+
|
| 837 |
+
A declaration `D` is *appearance-ordered* before a declaration `E` if
|
| 838 |
+
|
| 839 |
+
- `D` appears in the same translation unit as `E`, or
|
| 840 |
+
- the translation unit containing `E` has an interface dependency on the
|
| 841 |
+
translation unit containing `D`,
|
| 842 |
+
|
| 843 |
+
in either case prior to `E`.
|
| 844 |
+
|
| 845 |
+
Dynamic initialization of non-local variables `V` and `W` with static
|
| 846 |
+
storage duration are ordered as follows:
|
| 847 |
+
|
| 848 |
+
- If `V` and `W` have ordered initialization and the definition of `V`
|
| 849 |
+
is appearance-ordered before the definition of `W`, or if `V` has
|
| 850 |
+
partially-ordered initialization, `W` does not have unordered
|
| 851 |
+
initialization, and for every definition `E` of `W` there exists a
|
| 852 |
+
definition `D` of `V` such that `D` is appearance-ordered before `E`,
|
| 853 |
+
then
|
| 854 |
+
- if the program does not start a thread [[intro.multithread]] other
|
| 855 |
+
than the main thread [[basic.start.main]] or `V` and `W` have
|
| 856 |
+
ordered initialization and they are defined in the same translation
|
| 857 |
+
unit, the initialization of `V` is sequenced before the
|
| 858 |
+
initialization of `W`;
|
| 859 |
+
- otherwise, the initialization of `V` strongly happens before the
|
| 860 |
+
initialization of `W`.
|
| 861 |
+
- Otherwise, if the program starts a thread other than the main thread
|
| 862 |
+
before either `V` or `W` is initialized, it is unspecified in which
|
| 863 |
+
threads the initializations of `V` and `W` occur; the initializations
|
| 864 |
+
are unsequenced if they occur in the same thread.
|
| 865 |
+
- Otherwise, the initializations of `V` and `W` are indeterminately
|
| 866 |
+
sequenced.
|
| 867 |
+
|
| 868 |
+
[*Note 2*: This definition permits initialization of a sequence of
|
| 869 |
+
ordered variables concurrently with another sequence. — *end note*]
|
| 870 |
+
|
| 871 |
+
A *non-initialization odr-use* is an odr-use [[basic.def.odr]] not
|
| 872 |
+
caused directly or indirectly by the initialization of a non-local
|
| 873 |
+
static or thread storage duration variable.
|
| 874 |
+
|
| 875 |
+
It is *implementation-defined* whether the dynamic initialization of a
|
| 876 |
+
non-local non-inline variable with static storage duration is sequenced
|
| 877 |
+
before the first statement of `main` or is deferred. If it is deferred,
|
| 878 |
+
it strongly happens before any non-initialization odr-use of any
|
| 879 |
+
non-inline function or non-inline variable defined in the same
|
| 880 |
+
translation unit as the variable to be initialized. [^29] It is
|
| 881 |
+
*implementation-defined* in which threads and at which points in the
|
| 882 |
+
program such deferred dynamic initialization occurs.
|
| 883 |
+
|
| 884 |
+
[*Note 3*: Such points should be chosen in a way that allows the
|
| 885 |
+
programmer to avoid deadlocks. — *end note*]
|
| 886 |
+
|
| 887 |
+
[*Example 1*:
|
| 888 |
+
|
| 889 |
+
``` cpp
|
| 890 |
+
// - File 1 -
|
| 891 |
+
#include "a.h"
|
| 892 |
+
#include "b.h"
|
| 893 |
+
B b;
|
| 894 |
+
A::A(){
|
| 895 |
+
b.Use();
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
// - File 2 -
|
| 899 |
+
#include "a.h"
|
| 900 |
+
A a;
|
| 901 |
+
|
| 902 |
+
// - File 3 -
|
| 903 |
+
#include "a.h"
|
| 904 |
+
#include "b.h"
|
| 905 |
+
extern A a;
|
| 906 |
+
extern B b;
|
| 907 |
+
|
| 908 |
+
int main() {
|
| 909 |
+
a.Use();
|
| 910 |
+
b.Use();
|
| 911 |
+
}
|
| 912 |
+
```
|
| 913 |
+
|
| 914 |
+
It is *implementation-defined* whether either `a` or `b` is initialized
|
| 915 |
+
before `main` is entered or whether the initializations are delayed
|
| 916 |
+
until `a` is first odr-used in `main`. In particular, if `a` is
|
| 917 |
+
initialized before `main` is entered, it is not guaranteed that `b` will
|
| 918 |
+
be initialized before it is odr-used by the initialization of `a`, that
|
| 919 |
+
is, before `A::A` is called. If, however, `a` is initialized at some
|
| 920 |
+
point after the first statement of `main`, `b` will be initialized prior
|
| 921 |
+
to its use in `A::A`.
|
| 922 |
+
|
| 923 |
+
— *end example*]
|
| 924 |
+
|
| 925 |
+
It is *implementation-defined* whether the dynamic initialization of a
|
| 926 |
+
non-local inline variable with static storage duration is sequenced
|
| 927 |
+
before the first statement of `main` or is deferred. If it is deferred,
|
| 928 |
+
it strongly happens before any non-initialization odr-use of that
|
| 929 |
+
variable. It is *implementation-defined* in which threads and at which
|
| 930 |
+
points in the program such deferred dynamic initialization occurs.
|
| 931 |
+
|
| 932 |
+
It is *implementation-defined* whether the dynamic initialization of a
|
| 933 |
+
non-local non-inline variable with thread storage duration is sequenced
|
| 934 |
+
before the first statement of the initial function of a thread or is
|
| 935 |
+
deferred. If it is deferred, the initialization associated with the
|
| 936 |
+
entity for thread *t* is sequenced before the first non-initialization
|
| 937 |
+
odr-use by *t* of any non-inline variable with thread storage duration
|
| 938 |
+
defined in the same translation unit as the variable to be initialized.
|
| 939 |
+
It is *implementation-defined* in which threads and at which points in
|
| 940 |
+
the program such deferred dynamic initialization occurs.
|
| 941 |
+
|
| 942 |
+
If the initialization of a non-local variable with static or thread
|
| 943 |
+
storage duration exits via an exception, the function `std::terminate`
|
| 944 |
+
is called [[except.terminate]].
|
| 945 |
+
|
| 946 |
+
#### Termination <a id="basic.start.term">[[basic.start.term]]</a>
|
| 947 |
+
|
| 948 |
+
Constructed objects [[dcl.init]] with static storage duration are
|
| 949 |
+
destroyed and functions registered with `std::atexit` are called as part
|
| 950 |
+
of a call to `std::exit` [[support.start.term]]. The call to `std::exit`
|
| 951 |
+
is sequenced before the destructions and the registered functions.
|
| 952 |
+
|
| 953 |
+
[*Note 1*: Returning from `main` invokes `std::exit`
|
| 954 |
+
[[basic.start.main]]. — *end note*]
|
| 955 |
+
|
| 956 |
+
Constructed objects with thread storage duration within a given thread
|
| 957 |
+
are destroyed as a result of returning from the initial function of that
|
| 958 |
+
thread and as a result of that thread calling `std::exit`. The
|
| 959 |
+
destruction of all constructed objects with thread storage duration
|
| 960 |
+
within that thread strongly happens before destroying any object with
|
| 961 |
+
static storage duration.
|
| 962 |
+
|
| 963 |
+
If the completion of the constructor or dynamic initialization of an
|
| 964 |
+
object with static storage duration strongly happens before that of
|
| 965 |
+
another, the completion of the destructor of the second is sequenced
|
| 966 |
+
before the initiation of the destructor of the first. If the completion
|
| 967 |
+
of the constructor or dynamic initialization of an object with thread
|
| 968 |
+
storage duration is sequenced before that of another, the completion of
|
| 969 |
+
the destructor of the second is sequenced before the initiation of the
|
| 970 |
+
destructor of the first. If an object is initialized statically, the
|
| 971 |
+
object is destroyed in the same order as if the object was dynamically
|
| 972 |
+
initialized. For an object of array or class type, all subobjects of
|
| 973 |
+
that object are destroyed before any block-scope object with static
|
| 974 |
+
storage duration initialized during the construction of the subobjects
|
| 975 |
+
is destroyed. If the destruction of an object with static or thread
|
| 976 |
+
storage duration exits via an exception, the function `std::terminate`
|
| 977 |
+
is called [[except.terminate]].
|
| 978 |
+
|
| 979 |
+
If a function contains a block-scope object of static or thread storage
|
| 980 |
+
duration that has been destroyed and the function is called during the
|
| 981 |
+
destruction of an object with static or thread storage duration, the
|
| 982 |
+
program has undefined behavior if the flow of control passes through the
|
| 983 |
+
definition of the previously destroyed block-scope object. Likewise, the
|
| 984 |
+
behavior is undefined if the block-scope object is used indirectly
|
| 985 |
+
(i.e., through a pointer) after its destruction.
|
| 986 |
+
|
| 987 |
+
If the completion of the initialization of an object with static storage
|
| 988 |
+
duration strongly happens before a call to `std::atexit` (see
|
| 989 |
+
`<cstdlib>`, [[support.start.term]]), the call to the function passed to
|
| 990 |
+
`std::atexit` is sequenced before the call to the destructor for the
|
| 991 |
+
object. If a call to `std::atexit` strongly happens before the
|
| 992 |
+
completion of the initialization of an object with static storage
|
| 993 |
+
duration, the call to the destructor for the object is sequenced before
|
| 994 |
+
the call to the function passed to `std::atexit`. If a call to
|
| 995 |
+
`std::atexit` strongly happens before another call to `std::atexit`, the
|
| 996 |
+
call to the function passed to the second `std::atexit` call is
|
| 997 |
+
sequenced before the call to the function passed to the first
|
| 998 |
+
`std::atexit` call.
|
| 999 |
+
|
| 1000 |
+
If there is a use of a standard library object or function not permitted
|
| 1001 |
+
within signal handlers [[support.runtime]] that does not happen before
|
| 1002 |
+
[[intro.multithread]] completion of destruction of objects with static
|
| 1003 |
+
storage duration and execution of `std::atexit` registered functions
|
| 1004 |
+
[[support.start.term]], the program has undefined behavior.
|
| 1005 |
+
|
| 1006 |
+
[*Note 2*: If there is a use of an object with static storage duration
|
| 1007 |
+
that does not happen before the object’s destruction, the program has
|
| 1008 |
+
undefined behavior. Terminating every thread before a call to
|
| 1009 |
+
`std::exit` or the exit from `main` is sufficient, but not necessary, to
|
| 1010 |
+
satisfy these requirements. These requirements permit thread managers as
|
| 1011 |
+
static-storage-duration objects. — *end note*]
|
| 1012 |
+
|
| 1013 |
+
Calling the function `std::abort()` declared in `<cstdlib>` terminates
|
| 1014 |
+
the program without executing any destructors and without calling the
|
| 1015 |
+
functions passed to `std::atexit()` or `std::at_quick_exit()`.
|
| 1016 |
+
|
| 1017 |
+
<!-- Link reference definitions -->
|
| 1018 |
+
[allocator.members]: utilities.md#allocator.members
|
| 1019 |
+
[allocator.traits.members]: utilities.md#allocator.traits.members
|
| 1020 |
+
[atomics]: atomics.md#atomics
|
| 1021 |
+
[atomics.flag]: atomics.md#atomics.flag
|
| 1022 |
+
[atomics.lockfree]: atomics.md#atomics.lockfree
|
| 1023 |
+
[atomics.order]: atomics.md#atomics.order
|
| 1024 |
+
[bad.alloc]: support.md#bad.alloc
|
| 1025 |
+
[basic]: #basic
|
| 1026 |
+
[basic.align]: #basic.align
|
| 1027 |
+
[basic.compound]: #basic.compound
|
| 1028 |
+
[basic.def]: #basic.def
|
| 1029 |
+
[basic.def.odr]: #basic.def.odr
|
| 1030 |
+
[basic.exec]: #basic.exec
|
| 1031 |
+
[basic.fundamental]: #basic.fundamental
|
| 1032 |
+
[basic.fundamental.width]: #basic.fundamental.width
|
| 1033 |
+
[basic.funscope]: #basic.funscope
|
| 1034 |
+
[basic.indet]: #basic.indet
|
| 1035 |
+
[basic.life]: #basic.life
|
| 1036 |
+
[basic.link]: #basic.link
|
| 1037 |
+
[basic.lookup]: #basic.lookup
|
| 1038 |
+
[basic.lookup.argdep]: #basic.lookup.argdep
|
| 1039 |
+
[basic.lookup.classref]: #basic.lookup.classref
|
| 1040 |
+
[basic.lookup.elab]: #basic.lookup.elab
|
| 1041 |
+
[basic.lookup.qual]: #basic.lookup.qual
|
| 1042 |
+
[basic.lookup.udir]: #basic.lookup.udir
|
| 1043 |
+
[basic.lookup.unqual]: #basic.lookup.unqual
|
| 1044 |
+
[basic.lval]: expr.md#basic.lval
|
| 1045 |
+
[basic.memobj]: #basic.memobj
|
| 1046 |
+
[basic.namespace]: dcl.md#basic.namespace
|
| 1047 |
+
[basic.pre]: #basic.pre
|
| 1048 |
+
[basic.scope]: #basic.scope
|
| 1049 |
+
[basic.scope.block]: #basic.scope.block
|
| 1050 |
+
[basic.scope.class]: #basic.scope.class
|
| 1051 |
+
[basic.scope.declarative]: #basic.scope.declarative
|
| 1052 |
+
[basic.scope.enum]: #basic.scope.enum
|
| 1053 |
+
[basic.scope.hiding]: #basic.scope.hiding
|
| 1054 |
+
[basic.scope.namespace]: #basic.scope.namespace
|
| 1055 |
+
[basic.scope.param]: #basic.scope.param
|
| 1056 |
+
[basic.scope.pdecl]: #basic.scope.pdecl
|
| 1057 |
+
[basic.scope.temp]: #basic.scope.temp
|
| 1058 |
+
[basic.start]: #basic.start
|
| 1059 |
+
[basic.start.dynamic]: #basic.start.dynamic
|
| 1060 |
+
[basic.start.main]: #basic.start.main
|
| 1061 |
+
[basic.start.static]: #basic.start.static
|
| 1062 |
+
[basic.start.term]: #basic.start.term
|
| 1063 |
+
[basic.stc]: #basic.stc
|
| 1064 |
+
[basic.stc.auto]: #basic.stc.auto
|
| 1065 |
+
[basic.stc.dynamic]: #basic.stc.dynamic
|
| 1066 |
+
[basic.stc.dynamic.allocation]: #basic.stc.dynamic.allocation
|
| 1067 |
+
[basic.stc.dynamic.deallocation]: #basic.stc.dynamic.deallocation
|
| 1068 |
+
[basic.stc.dynamic.safety]: #basic.stc.dynamic.safety
|
| 1069 |
+
[basic.stc.inherit]: #basic.stc.inherit
|
| 1070 |
+
[basic.stc.static]: #basic.stc.static
|
| 1071 |
+
[basic.stc.thread]: #basic.stc.thread
|
| 1072 |
+
[basic.type.qualifier]: #basic.type.qualifier
|
| 1073 |
+
[basic.type.qualifier.rel]: #basic.type.qualifier.rel
|
| 1074 |
+
[basic.types]: #basic.types
|
| 1075 |
+
[bit.cast]: numerics.md#bit.cast
|
| 1076 |
+
[c.malloc]: utilities.md#c.malloc
|
| 1077 |
+
[class]: class.md#class
|
| 1078 |
+
[class.abstract]: class.md#class.abstract
|
| 1079 |
+
[class.access]: class.md#class.access
|
| 1080 |
+
[class.base.init]: class.md#class.base.init
|
| 1081 |
+
[class.bit]: class.md#class.bit
|
| 1082 |
+
[class.cdtor]: class.md#class.cdtor
|
| 1083 |
+
[class.conv.fct]: class.md#class.conv.fct
|
| 1084 |
+
[class.copy.assign]: class.md#class.copy.assign
|
| 1085 |
+
[class.copy.ctor]: class.md#class.copy.ctor
|
| 1086 |
+
[class.copy.elision]: class.md#class.copy.elision
|
| 1087 |
+
[class.default.ctor]: class.md#class.default.ctor
|
| 1088 |
+
[class.derived]: class.md#class.derived
|
| 1089 |
+
[class.dtor]: class.md#class.dtor
|
| 1090 |
+
[class.free]: class.md#class.free
|
| 1091 |
+
[class.friend]: class.md#class.friend
|
| 1092 |
+
[class.local]: class.md#class.local
|
| 1093 |
+
[class.mem]: class.md#class.mem
|
| 1094 |
+
[class.member.lookup]: class.md#class.member.lookup
|
| 1095 |
+
[class.mfct]: class.md#class.mfct
|
| 1096 |
+
[class.mfct.non-static]: class.md#class.mfct.non-static
|
| 1097 |
+
[class.name]: class.md#class.name
|
| 1098 |
+
[class.nest]: class.md#class.nest
|
| 1099 |
+
[class.pre]: class.md#class.pre
|
| 1100 |
+
[class.prop]: class.md#class.prop
|
| 1101 |
+
[class.qual]: #class.qual
|
| 1102 |
+
[class.spaceship]: class.md#class.spaceship
|
| 1103 |
+
[class.static]: class.md#class.static
|
| 1104 |
+
[class.static.data]: class.md#class.static.data
|
| 1105 |
+
[class.temporary]: #class.temporary
|
| 1106 |
+
[class.this]: class.md#class.this
|
| 1107 |
+
[class.union]: class.md#class.union
|
| 1108 |
+
[class.virtual]: class.md#class.virtual
|
| 1109 |
+
[conv]: expr.md#conv
|
| 1110 |
+
[conv.array]: expr.md#conv.array
|
| 1111 |
+
[conv.func]: expr.md#conv.func
|
| 1112 |
+
[conv.integral]: expr.md#conv.integral
|
| 1113 |
+
[conv.lval]: expr.md#conv.lval
|
| 1114 |
+
[conv.mem]: expr.md#conv.mem
|
| 1115 |
+
[conv.prom]: expr.md#conv.prom
|
| 1116 |
+
[conv.ptr]: expr.md#conv.ptr
|
| 1117 |
+
[conv.rank]: #conv.rank
|
| 1118 |
+
[conv.rval]: expr.md#conv.rval
|
| 1119 |
+
[cpp.predefined]: cpp.md#cpp.predefined
|
| 1120 |
+
[cstddef.syn]: support.md#cstddef.syn
|
| 1121 |
+
[cstring.syn]: strings.md#cstring.syn
|
| 1122 |
+
[dcl.align]: dcl.md#dcl.align
|
| 1123 |
+
[dcl.array]: dcl.md#dcl.array
|
| 1124 |
+
[dcl.attr]: dcl.md#dcl.attr
|
| 1125 |
+
[dcl.attr.nouniqueaddr]: dcl.md#dcl.attr.nouniqueaddr
|
| 1126 |
+
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 1127 |
+
[dcl.dcl]: dcl.md#dcl.dcl
|
| 1128 |
+
[dcl.decl]: dcl.md#dcl.decl
|
| 1129 |
+
[dcl.enum]: dcl.md#dcl.enum
|
| 1130 |
+
[dcl.fct]: dcl.md#dcl.fct
|
| 1131 |
+
[dcl.fct.def]: dcl.md#dcl.fct.def
|
| 1132 |
+
[dcl.fct.def.coroutine]: dcl.md#dcl.fct.def.coroutine
|
| 1133 |
+
[dcl.fct.def.general]: dcl.md#dcl.fct.def.general
|
| 1134 |
+
[dcl.fct.default]: dcl.md#dcl.fct.default
|
| 1135 |
+
[dcl.init]: dcl.md#dcl.init
|
| 1136 |
+
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 1137 |
+
[dcl.init.list]: dcl.md#dcl.init.list
|
| 1138 |
+
[dcl.init.ref]: dcl.md#dcl.init.ref
|
| 1139 |
+
[dcl.inline]: dcl.md#dcl.inline
|
| 1140 |
+
[dcl.link]: dcl.md#dcl.link
|
| 1141 |
+
[dcl.meaning]: dcl.md#dcl.meaning
|
| 1142 |
+
[dcl.mptr]: dcl.md#dcl.mptr
|
| 1143 |
+
[dcl.name]: dcl.md#dcl.name
|
| 1144 |
+
[dcl.pre]: dcl.md#dcl.pre
|
| 1145 |
+
[dcl.ptr]: dcl.md#dcl.ptr
|
| 1146 |
+
[dcl.ref]: dcl.md#dcl.ref
|
| 1147 |
+
[dcl.spec]: dcl.md#dcl.spec
|
| 1148 |
+
[dcl.spec.auto]: dcl.md#dcl.spec.auto
|
| 1149 |
+
[dcl.stc]: dcl.md#dcl.stc
|
| 1150 |
+
[dcl.struct.bind]: dcl.md#dcl.struct.bind
|
| 1151 |
+
[dcl.type.elab]: dcl.md#dcl.type.elab
|
| 1152 |
+
[dcl.typedef]: dcl.md#dcl.typedef
|
| 1153 |
+
[defns.block]: intro.md#defns.block
|
| 1154 |
+
[defns.signature]: intro.md#defns.signature
|
| 1155 |
+
[defns.signature.templ]: intro.md#defns.signature.templ
|
| 1156 |
+
[depr.local]: future.md#depr.local
|
| 1157 |
+
[depr.static.constexpr]: future.md#depr.static.constexpr
|
| 1158 |
+
[diff.cpp11.basic]: compatibility.md#diff.cpp11.basic
|
| 1159 |
+
[enum.udecl]: dcl.md#enum.udecl
|
| 1160 |
+
[except.handle]: except.md#except.handle
|
| 1161 |
+
[except.pre]: except.md#except.pre
|
| 1162 |
+
[except.spec]: except.md#except.spec
|
| 1163 |
+
[except.terminate]: except.md#except.terminate
|
| 1164 |
+
[except.throw]: except.md#except.throw
|
| 1165 |
+
[expr]: expr.md#expr
|
| 1166 |
+
[expr.add]: expr.md#expr.add
|
| 1167 |
+
[expr.alignof]: expr.md#expr.alignof
|
| 1168 |
+
[expr.arith.conv]: expr.md#expr.arith.conv
|
| 1169 |
+
[expr.ass]: expr.md#expr.ass
|
| 1170 |
+
[expr.await]: expr.md#expr.await
|
| 1171 |
+
[expr.call]: expr.md#expr.call
|
| 1172 |
+
[expr.cast]: expr.md#expr.cast
|
| 1173 |
+
[expr.comma]: expr.md#expr.comma
|
| 1174 |
+
[expr.compound]: expr.md#expr.compound
|
| 1175 |
+
[expr.cond]: expr.md#expr.cond
|
| 1176 |
+
[expr.const]: expr.md#expr.const
|
| 1177 |
+
[expr.const.cast]: expr.md#expr.const.cast
|
| 1178 |
+
[expr.context]: expr.md#expr.context
|
| 1179 |
+
[expr.delete]: expr.md#expr.delete
|
| 1180 |
+
[expr.dynamic.cast]: expr.md#expr.dynamic.cast
|
| 1181 |
+
[expr.eq]: expr.md#expr.eq
|
| 1182 |
+
[expr.log.and]: expr.md#expr.log.and
|
| 1183 |
+
[expr.log.or]: expr.md#expr.log.or
|
| 1184 |
+
[expr.mptr.oper]: expr.md#expr.mptr.oper
|
| 1185 |
+
[expr.new]: expr.md#expr.new
|
| 1186 |
+
[expr.pre]: expr.md#expr.pre
|
| 1187 |
+
[expr.prim.id]: expr.md#expr.prim.id
|
| 1188 |
+
[expr.prim.id.dtor]: expr.md#expr.prim.id.dtor
|
| 1189 |
+
[expr.prim.id.qual]: expr.md#expr.prim.id.qual
|
| 1190 |
+
[expr.prim.lambda]: expr.md#expr.prim.lambda
|
| 1191 |
+
[expr.prim.lambda.capture]: expr.md#expr.prim.lambda.capture
|
| 1192 |
+
[expr.prim.lambda.closure]: expr.md#expr.prim.lambda.closure
|
| 1193 |
+
[expr.prim.this]: expr.md#expr.prim.this
|
| 1194 |
+
[expr.prop]: expr.md#expr.prop
|
| 1195 |
+
[expr.ref]: expr.md#expr.ref
|
| 1196 |
+
[expr.reinterpret.cast]: expr.md#expr.reinterpret.cast
|
| 1197 |
+
[expr.rel]: expr.md#expr.rel
|
| 1198 |
+
[expr.sizeof]: expr.md#expr.sizeof
|
| 1199 |
+
[expr.static.cast]: expr.md#expr.static.cast
|
| 1200 |
+
[expr.sub]: expr.md#expr.sub
|
| 1201 |
+
[expr.type.conv]: expr.md#expr.type.conv
|
| 1202 |
+
[expr.typeid]: expr.md#expr.typeid
|
| 1203 |
+
[expr.unary.op]: expr.md#expr.unary.op
|
| 1204 |
+
[get.new.handler]: support.md#get.new.handler
|
| 1205 |
+
[headers]: library.md#headers
|
| 1206 |
+
[intro.execution]: #intro.execution
|
| 1207 |
+
[intro.memory]: #intro.memory
|
| 1208 |
+
[intro.multithread]: #intro.multithread
|
| 1209 |
+
[intro.object]: #intro.object
|
| 1210 |
+
[intro.progress]: #intro.progress
|
| 1211 |
+
[intro.races]: #intro.races
|
| 1212 |
+
[lex.charset]: lex.md#lex.charset
|
| 1213 |
+
[lex.name]: lex.md#lex.name
|
| 1214 |
+
[lex.separate]: lex.md#lex.separate
|
| 1215 |
+
[locale]: localization.md#locale
|
| 1216 |
+
[meta.trans.other]: utilities.md#meta.trans.other
|
| 1217 |
+
[module.context]: module.md#module.context
|
| 1218 |
+
[module.global.frag]: module.md#module.global.frag
|
| 1219 |
+
[module.import]: module.md#module.import
|
| 1220 |
+
[module.interface]: module.md#module.interface
|
| 1221 |
+
[module.reach]: module.md#module.reach
|
| 1222 |
+
[module.unit]: module.md#module.unit
|
| 1223 |
+
[multibyte.strings]: library.md#multibyte.strings
|
| 1224 |
+
[namespace.def]: dcl.md#namespace.def
|
| 1225 |
+
[namespace.memdef]: dcl.md#namespace.memdef
|
| 1226 |
+
[namespace.qual]: #namespace.qual
|
| 1227 |
+
[namespace.udecl]: dcl.md#namespace.udecl
|
| 1228 |
+
[namespace.udir]: dcl.md#namespace.udir
|
| 1229 |
+
[new.delete]: support.md#new.delete
|
| 1230 |
+
[new.delete.array]: support.md#new.delete.array
|
| 1231 |
+
[new.delete.placement]: support.md#new.delete.placement
|
| 1232 |
+
[new.delete.single]: support.md#new.delete.single
|
| 1233 |
+
[new.handler]: support.md#new.handler
|
| 1234 |
+
[over]: over.md#over
|
| 1235 |
+
[over.literal]: over.md#over.literal
|
| 1236 |
+
[over.match]: over.md#over.match
|
| 1237 |
+
[over.oper]: over.md#over.oper
|
| 1238 |
+
[over.over]: over.md#over.over
|
| 1239 |
+
[ptr.align]: utilities.md#ptr.align
|
| 1240 |
+
[ptr.launder]: support.md#ptr.launder
|
| 1241 |
+
[replacement.functions]: library.md#replacement.functions
|
| 1242 |
+
[special]: class.md#special
|
| 1243 |
+
[stmt.block]: stmt.md#stmt.block
|
| 1244 |
+
[stmt.dcl]: stmt.md#stmt.dcl
|
| 1245 |
+
[stmt.expr]: stmt.md#stmt.expr
|
| 1246 |
+
[stmt.goto]: stmt.md#stmt.goto
|
| 1247 |
+
[stmt.if]: stmt.md#stmt.if
|
| 1248 |
+
[stmt.label]: stmt.md#stmt.label
|
| 1249 |
+
[stmt.ranged]: stmt.md#stmt.ranged
|
| 1250 |
+
[stmt.return]: stmt.md#stmt.return
|
| 1251 |
+
[support.dynamic]: support.md#support.dynamic
|
| 1252 |
+
[support.limits]: support.md#support.limits
|
| 1253 |
+
[support.runtime]: support.md#support.runtime
|
| 1254 |
+
[support.start.term]: support.md#support.start.term
|
| 1255 |
+
[support.types]: support.md#support.types
|
| 1256 |
+
[temp.deduct.guide]: temp.md#temp.deduct.guide
|
| 1257 |
+
[temp.dep]: temp.md#temp.dep
|
| 1258 |
+
[temp.dep.candidate]: temp.md#temp.dep.candidate
|
| 1259 |
+
[temp.expl.spec]: temp.md#temp.expl.spec
|
| 1260 |
+
[temp.explicit]: temp.md#temp.explicit
|
| 1261 |
+
[temp.local]: temp.md#temp.local
|
| 1262 |
+
[temp.names]: temp.md#temp.names
|
| 1263 |
+
[temp.nondep]: temp.md#temp.nondep
|
| 1264 |
+
[temp.over]: temp.md#temp.over
|
| 1265 |
+
[temp.param]: temp.md#temp.param
|
| 1266 |
+
[temp.point]: temp.md#temp.point
|
| 1267 |
+
[temp.pre]: temp.md#temp.pre
|
| 1268 |
+
[temp.res]: temp.md#temp.res
|
| 1269 |
+
[temp.spec]: temp.md#temp.spec
|
| 1270 |
+
[temp.type]: temp.md#temp.type
|
| 1271 |
+
[thread]: thread.md#thread
|
| 1272 |
+
[thread.jthread.class]: thread.md#thread.jthread.class
|
| 1273 |
+
[thread.thread.class]: thread.md#thread.thread.class
|
| 1274 |
+
[thread.threads]: thread.md#thread.threads
|
| 1275 |
+
[util.dynamic.safety]: utilities.md#util.dynamic.safety
|
| 1276 |
+
|
| 1277 |
+
[^1]: Appearing inside the brace-enclosed *declaration-seq* in a
|
| 1278 |
+
*linkage-specification* does not affect whether a declaration is a
|
| 1279 |
+
definition.
|
| 1280 |
+
|
| 1281 |
+
[^2]: An implementation is not required to call allocation and
|
| 1282 |
+
deallocation functions from constructors or destructors; however,
|
| 1283 |
+
this is a permissible implementation technique.
|
| 1284 |
+
|
| 1285 |
+
[^3]: This refers to unqualified names that occur, for instance, in a
|
| 1286 |
+
type or default argument in the *parameter-declaration-clause* or
|
| 1287 |
+
used in the function body.
|
| 1288 |
+
|
| 1289 |
+
[^4]: This refers to unqualified names following the class name; such a
|
| 1290 |
+
name may be used in a *base-specifier* or in the
|
| 1291 |
+
*member-specification* of the class definition.
|
| 1292 |
+
|
| 1293 |
+
[^5]: This lookup applies whether the definition of `X` is nested within
|
| 1294 |
+
`Y`’s definition or whether `X`’s definition appears in a namespace
|
| 1295 |
+
scope enclosing `Y`’s definition [[class.nest]].
|
| 1296 |
+
|
| 1297 |
+
[^6]: That is, an unqualified name that occurs, for instance, in a type
|
| 1298 |
+
in the *parameter-declaration-clause* or in the
|
| 1299 |
+
*noexcept-specifier*.
|
| 1300 |
+
|
| 1301 |
+
[^7]: This lookup applies whether the member function is defined within
|
| 1302 |
+
the definition of class `X` or whether the member function is
|
| 1303 |
+
defined in a namespace scope enclosing `X`’s definition.
|
| 1304 |
+
|
| 1305 |
+
[^8]: Lookups in which function names are ignored include names
|
| 1306 |
+
appearing in a *nested-name-specifier*, an
|
| 1307 |
+
*elaborated-type-specifier*, or a *base-specifier*.
|
| 1308 |
+
|
| 1309 |
+
[^9]: The number of bits in a byte is reported by the macro `CHAR_BIT`
|
| 1310 |
+
in the header `<climits>`.
|
| 1311 |
+
|
| 1312 |
+
[^10]: Under the “as-if” rule an implementation is allowed to store two
|
| 1313 |
+
objects at the same machine address or not store an object at all if
|
| 1314 |
+
the program cannot observe the difference [[intro.execution]].
|
| 1315 |
+
|
| 1316 |
+
[^11]: For example, before the construction of a global object that is
|
| 1317 |
+
initialized via a user-provided constructor [[class.cdtor]].
|
| 1318 |
+
|
| 1319 |
+
[^12]: That is, an object for which a destructor will be called
|
| 1320 |
+
implicitly—upon exit from the block for an object with automatic
|
| 1321 |
+
storage duration, upon exit from the thread for an object with
|
| 1322 |
+
thread storage duration, or upon exit from the program for an object
|
| 1323 |
+
with static storage duration.
|
| 1324 |
+
|
| 1325 |
+
[^13]: Some implementations might define that copying an invalid pointer
|
| 1326 |
+
value causes a system-generated runtime fault.
|
| 1327 |
+
|
| 1328 |
+
[^14]: The intent is to have `operator new()` implementable by calling
|
| 1329 |
+
`std::malloc()` or `std::calloc()`, so the rules are substantially
|
| 1330 |
+
the same. C++ differs from C in requiring a zero request to return a
|
| 1331 |
+
non-null pointer.
|
| 1332 |
+
|
| 1333 |
+
[^15]: The global `operator delete(void*, std::size_t)` precludes use of
|
| 1334 |
+
an allocation function `void operator new(std::size_t, std::size_t)`
|
| 1335 |
+
as a placement allocation function ([[diff.cpp11.basic]]).
|
| 1336 |
+
|
| 1337 |
+
[^16]: This subclause does not impose restrictions on indirection
|
| 1338 |
+
through pointers to memory not allocated by `::operator new`. This
|
| 1339 |
+
maintains the ability of many C++ implementations to use binary
|
| 1340 |
+
libraries and components written in other languages. In particular,
|
| 1341 |
+
this applies to C binaries, because indirection through pointers to
|
| 1342 |
+
memory allocated by `std::malloc` is not restricted.
|
| 1343 |
+
|
| 1344 |
+
[^17]: The same rules apply to initialization of an `initializer_list`
|
| 1345 |
+
object [[dcl.init.list]] with its underlying temporary array.
|
| 1346 |
+
|
| 1347 |
+
[^18]: By using, for example, the library functions [[headers]]
|
| 1348 |
+
`std::memcpy` or `std::memmove`.
|
| 1349 |
+
|
| 1350 |
+
[^19]: By using, for example, the library functions [[headers]]
|
| 1351 |
+
`std::memcpy` or `std::memmove`.
|
| 1352 |
+
|
| 1353 |
+
[^20]: The intent is that the memory model of C++ is compatible with
|
| 1354 |
+
that of ISO/IEC 9899 Programming Language C.
|
| 1355 |
+
|
| 1356 |
+
[^21]: The size and layout of an instance of an incompletely-defined
|
| 1357 |
+
object type is unknown.
|
| 1358 |
+
|
| 1359 |
+
[^22]: This is also known as two’s complement representation.
|
| 1360 |
+
|
| 1361 |
+
[^23]: Static class members are objects or functions, and pointers to
|
| 1362 |
+
them are ordinary pointers to objects or functions.
|
| 1363 |
+
|
| 1364 |
+
[^24]: For an object that is not within its lifetime, this is the first
|
| 1365 |
+
byte in memory that it will occupy or used to occupy.
|
| 1366 |
+
|
| 1367 |
+
[^25]: The same representation and alignment requirements are meant to
|
| 1368 |
+
imply interchangeability as arguments to functions, return values
|
| 1369 |
+
from functions, and non-static data members of unions.
|
| 1370 |
+
|
| 1371 |
+
[^26]: As specified in [[class.temporary]], after a full-expression is
|
| 1372 |
+
evaluated, a sequence of zero or more invocations of destructor
|
| 1373 |
+
functions for temporary objects takes place, usually in reverse
|
| 1374 |
+
order of the construction of each temporary object.
|
| 1375 |
+
|
| 1376 |
+
[^27]: In other words, function executions do not interleave with each
|
| 1377 |
+
other.
|
| 1378 |
+
|
| 1379 |
+
[^28]: An object with automatic or thread storage duration [[basic.stc]]
|
| 1380 |
+
is associated with one specific thread, and can be accessed by a
|
| 1381 |
+
different thread only indirectly through a pointer or reference
|
| 1382 |
+
[[basic.compound]].
|
| 1383 |
+
|
| 1384 |
+
[^29]: A non-local variable with static storage duration having
|
| 1385 |
+
initialization with side effects is initialized in this case, even
|
| 1386 |
+
if it is not itself odr-used ([[basic.def.odr]],
|
| 1387 |
+
[[basic.stc.static]]).
|