- tmp/tmp2ko3c0p0/{from.md → to.md} +206 -202
tmp/tmp2ko3c0p0/{from.md → to.md}
RENAMED
|
@@ -9,10 +9,12 @@ 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
|
|
@@ -50,13 +52,20 @@ 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.
|
| 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,
|
|
@@ -140,20 +149,20 @@ overlap. — *end note*]
|
|
| 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
|
| 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.[^
|
| 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
|
|
@@ -184,22 +193,23 @@ void g(int i) {
|
|
| 184 |
}
|
| 185 |
```
|
| 186 |
|
| 187 |
— *end example*]
|
| 188 |
|
| 189 |
-
When
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
|
|
|
| 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
|
|
@@ -208,37 +218,40 @@ 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 |
-
|
| 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
|
| 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.[^
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
| 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*]
|
|
@@ -255,12 +268,12 @@ contains the signal handler invocation.
|
|
| 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
|
| 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
|
|
@@ -293,11 +306,11 @@ 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 |
-
|
| 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
|
|
@@ -506,12 +519,12 @@ 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
|
| 512 |
-
|
| 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
|
|
@@ -527,17 +540,17 @@ 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
|
| 533 |
-
also generally precluded, since this
|
| 534 |
rules. — *end note*]
|
| 535 |
|
| 536 |
[*Note 23*: Transformations that introduce a speculative read of a
|
| 537 |
-
potentially shared memory location
|
| 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*]
|
|
@@ -560,25 +573,25 @@ 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
|
| 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
|
| 573 |
forward progress, e.g., by repeatedly stealing a cache line for
|
| 574 |
unrelated purposes between load-locked and store-conditional
|
| 575 |
-
instructions.
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
Outside this document, this property is
|
| 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,
|
|
@@ -590,11 +603,11 @@ 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
|
| 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
|
|
@@ -609,30 +622,28 @@ concurrent threads that are not blocked in a standard library function
|
|
| 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
|
| 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
|
| 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
|
|
@@ -640,57 +651,57 @@ 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
|
| 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
|
| 657 |
-
of execution
|
| 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
|
| 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
|
| 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
|
| 683 |
provide a stronger forward progress guarantee to C. — *end note*]
|
| 684 |
|
| 685 |
-
[*Note
|
| 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
|
| 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 |
|
|
@@ -700,28 +711,26 @@ 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
|
| 706 |
-
global
|
| 707 |
-
[[intro.multithread]], [[thread.threads]]
|
| 708 |
-
is invoked
|
| 709 |
-
|
| 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
|
| 716 |
-
|
| 717 |
duration. — *end note*]
|
| 718 |
|
| 719 |
-
An implementation shall not predefine the `main` function.
|
| 720 |
-
shall
|
| 721 |
-
|
| 722 |
-
|
| 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
|
|
@@ -734,33 +743,37 @@ 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 |
-
|
| 740 |
-
added after `argv`.
|
| 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 `
|
| 746 |
-
a coroutine [[dcl.fct.def.coroutine]]. The `main` function
|
| 747 |
-
declared with a *linkage-specification* [[dcl.link]]. A
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 760 |
-
|
| 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
|
|
@@ -778,16 +791,16 @@ phases of initiation, initialization occurs as follows.
|
|
| 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
|
| 784 |
-
initialization*. All static initialization strongly happens
|
| 785 |
-
[[intro.races]] any dynamic initialization.
|
| 786 |
|
| 787 |
-
[*Note 1*: The dynamic initialization of non-
|
| 788 |
-
described in [[basic.start.dynamic]]; that of
|
| 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
|
|
@@ -802,49 +815,48 @@ statically, provided that
|
|
| 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`
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
|
| 813 |
``` cpp
|
| 814 |
inline double fd() { return 1.0; }
|
| 815 |
extern double d1;
|
| 816 |
double d2 = d1; // unspecified:
|
| 817 |
-
//
|
| 818 |
// dynamically initialized to 0.0 if d1 is
|
| 819 |
// dynamically initialized, or 1.0 otherwise
|
| 820 |
-
double d1 = fd(); //
|
| 821 |
```
|
| 822 |
|
| 823 |
— *end note*]
|
| 824 |
|
| 825 |
-
#### Dynamic initialization of non-
|
| 826 |
|
| 827 |
-
Dynamic initialization of a non-
|
| 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*:
|
| 834 |
-
|
| 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-
|
| 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
|
|
@@ -866,25 +878,26 @@ storage duration are ordered as follows:
|
|
| 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 [[
|
| 872 |
-
|
| 873 |
-
|
| 874 |
|
| 875 |
It is *implementation-defined* whether the dynamic initialization of a
|
| 876 |
-
non-
|
| 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.
|
| 881 |
-
*implementation-defined* in which threads and at which points in the
|
| 882 |
-
program such deferred dynamic initialization occurs.
|
| 883 |
|
| 884 |
-
|
| 885 |
-
|
|
|
|
|
|
|
|
|
|
| 886 |
|
| 887 |
[*Example 1*:
|
| 888 |
|
| 889 |
``` cpp
|
| 890 |
// - File 1 -
|
|
@@ -921,27 +934,27 @@ 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-
|
| 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-
|
| 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-
|
| 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 |
|
|
@@ -968,23 +981,25 @@ 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
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
|
| 978 |
|
| 979 |
-
If a function contains a block
|
| 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
|
| 984 |
-
|
| 985 |
-
|
|
|
|
|
|
|
| 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
|
|
@@ -1001,11 +1016,11 @@ 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
|
| 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*]
|
|
@@ -1013,49 +1028,50 @@ static-storage-duration objects. — *end note*]
|
|
| 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]:
|
| 1019 |
-
[allocator.traits.members]:
|
| 1020 |
-
[atomics]:
|
| 1021 |
-
[atomics.flag]:
|
| 1022 |
-
[atomics.lockfree]:
|
| 1023 |
-
[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.
|
| 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
|
|
@@ -1063,22 +1079,25 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
|
|
| 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.
|
|
|
|
| 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 |
-
[
|
| 1076 |
-
[
|
|
|
|
| 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
|
|
@@ -1087,26 +1106,24 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
|
|
| 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]:
|
| 1095 |
[class.mfct]: class.md#class.mfct
|
| 1096 |
-
[class.mfct.non
|
| 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
|
|
@@ -1134,11 +1151,10 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
|
|
| 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
|
|
@@ -1146,34 +1162,31 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
|
|
| 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
|
|
@@ -1183,12 +1196,12 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
|
|
| 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
|
|
@@ -1204,184 +1217,175 @@ functions passed to `std::atexit()` or `std::at_quick_exit()`.
|
|
| 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]:
|
| 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.
|
|
|
|
| 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]:
|
| 1286 |
-
|
| 1287 |
-
used in the function body.
|
| 1288 |
|
| 1289 |
-
[^4]:
|
| 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 |
-
[^
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1310 |
in the header `<climits>`.
|
| 1311 |
|
| 1312 |
-
[^
|
| 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 |
-
[^
|
| 1317 |
-
|
| 1318 |
|
| 1319 |
-
[^
|
| 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 |
-
[^
|
| 1326 |
value causes a system-generated runtime fault.
|
| 1327 |
|
| 1328 |
-
[^
|
| 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 |
-
[^
|
| 1334 |
an allocation function `void operator new(std::size_t, std::size_t)`
|
| 1335 |
-
as a placement allocation function
|
| 1336 |
|
| 1337 |
-
[^
|
| 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 |
-
[^
|
| 1348 |
`std::memcpy` or `std::memmove`.
|
| 1349 |
|
| 1350 |
-
[^
|
| 1351 |
`std::memcpy` or `std::memmove`.
|
| 1352 |
|
| 1353 |
-
[^
|
| 1354 |
that of ISO/IEC 9899 Programming Language C.
|
| 1355 |
|
| 1356 |
-
[^
|
| 1357 |
object type is unknown.
|
| 1358 |
|
| 1359 |
-
[^
|
| 1360 |
|
| 1361 |
-
[^
|
| 1362 |
them are ordinary pointers to objects or functions.
|
| 1363 |
|
| 1364 |
-
[^
|
| 1365 |
byte in memory that it will occupy or used to occupy.
|
| 1366 |
|
| 1367 |
-
[^
|
| 1368 |
imply interchangeability as arguments to functions, return values
|
| 1369 |
from functions, and non-static data members of unions.
|
| 1370 |
|
| 1371 |
-
[^
|
| 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 |
-
[^
|
| 1377 |
other.
|
| 1378 |
|
| 1379 |
-
[^
|
| 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 |
-
[^
|
| 1385 |
initialization with side effects is initialized in this case, even
|
| 1386 |
-
if it is not itself odr-used
|
| 1387 |
-
[[basic.stc.static]]).
|
|
|
|
| 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 expression of a conversion is the corresponding
|
| 15 |
+
implicit function call, if any, or the converted expression otherwise.
|
| 16 |
- The constituent expressions of a *braced-init-list* or of a (possibly
|
| 17 |
parenthesized) *expression-list* are the constituent expressions of
|
| 18 |
the elements of the respective list.
|
| 19 |
- The constituent expressions of a *brace-or-equal-initializer* of the
|
| 20 |
form `=` *initializer-clause* are the constituent expressions of the
|
|
|
|
| 52 |
|
| 53 |
[*Note 1*: Expressions appearing in the *compound-statement* of a
|
| 54 |
*lambda-expression* are not subexpressions of the
|
| 55 |
*lambda-expression*. — *end note*]
|
| 56 |
|
| 57 |
+
The *potentially-evaluated subexpressions* of an expression, conversion,
|
| 58 |
+
or *initializer* E are
|
| 59 |
+
|
| 60 |
+
- the constituent expressions of E and
|
| 61 |
+
- the subexpressions thereof that are not subexpressions of a nested
|
| 62 |
+
unevaluated operand [[term.unevaluated.operand]].
|
| 63 |
+
|
| 64 |
A *full-expression* is
|
| 65 |
|
| 66 |
+
- an unevaluated operand [[expr.context]],
|
| 67 |
- a *constant-expression* [[expr.const]],
|
| 68 |
- an immediate invocation [[expr.const]],
|
| 69 |
- an *init-declarator* [[dcl.decl]] or a *mem-initializer*
|
| 70 |
[[class.base.init]], including the constituent expressions of the
|
| 71 |
initializer,
|
|
|
|
| 149 |
Evaluations *A* and *B* are *indeterminately sequenced* when either *A*
|
| 150 |
is sequenced before *B* or *B* is sequenced before *A*, but it is
|
| 151 |
unspecified which.
|
| 152 |
|
| 153 |
[*Note 4*: Indeterminately sequenced evaluations cannot overlap, but
|
| 154 |
+
either can be executed first. — *end note*]
|
| 155 |
|
| 156 |
An expression *X* is said to be sequenced before an expression *Y* if
|
| 157 |
every value computation and every side effect associated with the
|
| 158 |
expression *X* is sequenced before every value computation and every
|
| 159 |
side effect associated with the expression *Y*.
|
| 160 |
|
| 161 |
Every value computation and side effect associated with a
|
| 162 |
full-expression is sequenced before every value computation and side
|
| 163 |
+
effect associated with the next full-expression to be evaluated.[^22]
|
| 164 |
|
| 165 |
Except where noted, evaluations of operands of individual operators and
|
| 166 |
of subexpressions of individual expressions are unsequenced.
|
| 167 |
|
| 168 |
[*Note 5*: In an expression that is evaluated more than once during the
|
|
|
|
| 193 |
}
|
| 194 |
```
|
| 195 |
|
| 196 |
— *end example*]
|
| 197 |
|
| 198 |
+
When invoking a function (whether or not the function is inline), every
|
| 199 |
+
argument expression and the postfix expression designating the called
|
| 200 |
+
function are sequenced before every expression or statement in the body
|
| 201 |
+
of the called function. For each function invocation or evaluation of an
|
| 202 |
+
*await-expression* *F*, each evaluation that does not occur within *F*
|
| 203 |
+
but is evaluated on the same thread and as part of the same signal
|
| 204 |
+
handler (if any) is either sequenced before all evaluations that occur
|
| 205 |
+
within *F* or sequenced after all evaluations that occur within
|
| 206 |
+
*F*;[^23]
|
| 207 |
|
| 208 |
+
if *F* invokes or resumes a coroutine [[expr.await]], only evaluations
|
| 209 |
+
subsequent to the previous suspension (if any) and prior to the next
|
| 210 |
+
suspension (if any) are considered to occur within *F*.
|
| 211 |
|
| 212 |
Several contexts in C++ cause evaluation of a function call, even though
|
| 213 |
no corresponding function call syntax appears in the translation unit.
|
| 214 |
|
| 215 |
[*Example 4*: Evaluation of a *new-expression* invokes one or more
|
|
|
|
| 218 |
arise in contexts in which no function call syntax
|
| 219 |
appears. — *end example*]
|
| 220 |
|
| 221 |
The sequencing constraints on the execution of the called function (as
|
| 222 |
described above) are features of the function calls as evaluated,
|
| 223 |
+
regardless of the syntax of the expression that calls the function.
|
| 224 |
|
| 225 |
If a signal handler is executed as a result of a call to the
|
| 226 |
`std::raise` function, then the execution of the handler is sequenced
|
| 227 |
after the invocation of the `std::raise` function and before its return.
|
| 228 |
|
| 229 |
+
[*Note 7*: When a signal is received for another reason, the execution
|
| 230 |
of the signal handler is usually unsequenced with respect to the rest of
|
| 231 |
the program. — *end note*]
|
| 232 |
|
| 233 |
### Multi-threaded executions and data races <a id="intro.multithread">[[intro.multithread]]</a>
|
| 234 |
|
| 235 |
+
#### General <a id="intro.multithread.general">[[intro.multithread.general]]</a>
|
| 236 |
+
|
| 237 |
A *thread of execution* (also known as a *thread*) is a single flow of
|
| 238 |
control within a program, including the initial invocation of a specific
|
| 239 |
top-level function, and recursively including every function invocation
|
| 240 |
subsequently executed by the thread.
|
| 241 |
|
| 242 |
[*Note 1*: When one thread creates another, the initial call to the
|
| 243 |
top-level function of the new thread is executed by the new thread, not
|
| 244 |
by the creating thread. — *end note*]
|
| 245 |
|
| 246 |
Every thread in a program can potentially access every object and
|
| 247 |
+
function in a program.[^24]
|
| 248 |
+
|
| 249 |
+
Under a hosted implementation, a C++ program can have more than one
|
| 250 |
+
thread running concurrently. The execution of each thread proceeds as
|
| 251 |
+
defined by the remainder of this document. The execution of the entire
|
| 252 |
+
program consists of an execution of all of its threads.
|
| 253 |
|
| 254 |
[*Note 2*: Usually the execution can be viewed as an interleaving of
|
| 255 |
all its threads. However, some kinds of atomic operations, for example,
|
| 256 |
allow executions inconsistent with a simple interleaving, as described
|
| 257 |
below. — *end note*]
|
|
|
|
| 268 |
The value of an object visible to a thread T at a particular point is
|
| 269 |
the initial value of the object, a value assigned to the object by T, or
|
| 270 |
a value assigned to the object by another thread, according to the rules
|
| 271 |
below.
|
| 272 |
|
| 273 |
+
[*Note 1*: In some cases, there might instead be undefined behavior.
|
| 274 |
+
Much of this subclause is motivated by the desire to support atomic
|
| 275 |
operations with explicit and detailed visibility constraints. However,
|
| 276 |
it also implicitly supports a simpler view for more restricted
|
| 277 |
programs. — *end note*]
|
| 278 |
|
| 279 |
Two expression evaluations *conflict* if one of them modifies a memory
|
|
|
|
| 306 |
particular total order, called the *modification order* of M.
|
| 307 |
|
| 308 |
[*Note 3*: There is a separate order for each atomic object. There is
|
| 309 |
no requirement that these can be combined into a single total order for
|
| 310 |
all objects. In general this will be impossible since different threads
|
| 311 |
+
can observe modifications to different objects in inconsistent
|
| 312 |
orders. — *end note*]
|
| 313 |
|
| 314 |
A *release sequence* headed by a release operation A on an atomic object
|
| 315 |
M is a maximal contiguous sub-sequence of side effects in the
|
| 316 |
modification order of M, where the first operation is A, and every
|
|
|
|
| 519 |
object in that interleaving. This is normally referred to as “sequential
|
| 520 |
consistency”. However, this applies only to data-race-free programs, and
|
| 521 |
data-race-free programs cannot observe most program transformations that
|
| 522 |
do not change single-threaded program semantics. In fact, most
|
| 523 |
single-threaded program transformations continue to be allowed, since
|
| 524 |
+
any program that behaves differently as a result has undefined
|
| 525 |
+
behavior. — *end note*]
|
| 526 |
|
| 527 |
Two accesses to the same object of type `volatile std::sig_atomic_t` do
|
| 528 |
not result in a data race if both occur in the same thread, even if one
|
| 529 |
or more occurs in a signal handler. For each signal handler invocation,
|
| 530 |
evaluations performed by the thread invoking a signal handler can be
|
|
|
|
| 540 |
abstract machine are generally precluded by this document, since such an
|
| 541 |
assignment might overwrite another assignment by a different thread in
|
| 542 |
cases in which an abstract machine execution would not have encountered
|
| 543 |
a data race. This includes implementations of data member assignment
|
| 544 |
that overwrite adjacent members in separate memory locations. Reordering
|
| 545 |
+
of atomic loads in cases in which the atomics in question might alias is
|
| 546 |
+
also generally precluded, since this could violate the coherence
|
| 547 |
rules. — *end note*]
|
| 548 |
|
| 549 |
[*Note 23*: Transformations that introduce a speculative read of a
|
| 550 |
+
potentially shared memory location might not preserve the semantics of
|
| 551 |
+
the C++ program as defined in this document, since they potentially
|
| 552 |
introduce a data race. However, they are typically valid in the context
|
| 553 |
of an optimizing compiler that targets a specific machine with
|
| 554 |
well-defined semantics for data races. They would be invalid for a
|
| 555 |
hypothetical machine that is not tolerant of races or provides hardware
|
| 556 |
race detection. — *end note*]
|
|
|
|
| 573 |
[[atomics.flag]] or indicated as lock-free [[atomics.lockfree]] are
|
| 574 |
*lock-free executions*.
|
| 575 |
|
| 576 |
- If there is only one thread that is not blocked [[defns.block]] in a
|
| 577 |
standard library function, a lock-free execution in that thread shall
|
| 578 |
+
complete. \[*Note 2*: Concurrently executing threads might prevent
|
| 579 |
progress of a lock-free execution. For example, this situation can
|
| 580 |
occur with load-locked store-conditional implementations. This
|
| 581 |
property is sometimes termed obstruction-free. — *end note*]
|
| 582 |
- When one or more lock-free executions run concurrently, at least one
|
| 583 |
should complete. \[*Note 3*: It is difficult for some implementations
|
| 584 |
to provide absolute guarantees to this effect, since repeated and
|
| 585 |
+
particularly inopportune interference from other threads could prevent
|
| 586 |
forward progress, e.g., by repeatedly stealing a cache line for
|
| 587 |
unrelated purposes between load-locked and store-conditional
|
| 588 |
+
instructions. For implementations that follow this recommendation and
|
| 589 |
+
ensure that such effects cannot indefinitely delay progress under
|
| 590 |
+
expected operating conditions, such anomalies can therefore safely be
|
| 591 |
+
ignored by programmers. Outside this document, this property is
|
| 592 |
+
sometimes termed lock-free. — *end note*]
|
| 593 |
|
| 594 |
During the execution of a thread of execution, each of the following is
|
| 595 |
termed an *execution step*:
|
| 596 |
|
| 597 |
- termination of the thread of execution,
|
|
|
|
| 603 |
is considered to continuously execute execution steps while waiting for
|
| 604 |
the condition that it blocks on to be satisfied.
|
| 605 |
|
| 606 |
[*Example 1*: A library I/O function that blocks until the I/O
|
| 607 |
operation is complete can be considered to continuously check whether
|
| 608 |
+
the operation is complete. Each such check consists of one or more
|
| 609 |
execution steps, for example using observable behavior of the abstract
|
| 610 |
machine. — *end example*]
|
| 611 |
|
| 612 |
[*Note 4*: Because of this and the preceding requirement regarding what
|
| 613 |
threads of execution have to perform eventually, it follows that no
|
|
|
|
| 622 |
For a thread of execution providing *concurrent forward progress
|
| 623 |
guarantees*, the implementation ensures that the thread will eventually
|
| 624 |
make progress for as long as it has not terminated.
|
| 625 |
|
| 626 |
[*Note 5*: This is required regardless of whether or not other threads
|
| 627 |
+
of execution (if any) have been or are making progress. To eventually
|
| 628 |
fulfill this requirement means that this will happen in an unspecified
|
| 629 |
but finite amount of time. — *end note*]
|
| 630 |
|
| 631 |
It is *implementation-defined* whether the implementation-created thread
|
| 632 |
of execution that executes `main` [[basic.start.main]] and the threads
|
| 633 |
of execution created by `std::thread` [[thread.thread.class]] or
|
| 634 |
`std::jthread` [[thread.jthread.class]] provide concurrent forward
|
| 635 |
+
progress guarantees. General-purpose implementations should provide
|
| 636 |
+
these guarantees.
|
|
|
|
|
|
|
| 637 |
|
| 638 |
For a thread of execution providing *parallel forward progress
|
| 639 |
guarantees*, the implementation is not required to ensure that the
|
| 640 |
thread will eventually make progress if it has not yet executed any
|
| 641 |
execution step; once this thread has executed a step, it provides
|
| 642 |
concurrent forward progress guarantees.
|
| 643 |
|
| 644 |
+
[*Note 6*: This does not specify a requirement for when to start this
|
| 645 |
thread of execution, which will typically be specified by the entity
|
| 646 |
that creates this thread of execution. For example, a thread of
|
| 647 |
execution that provides concurrent forward progress guarantees and
|
| 648 |
executes tasks from a set of tasks in an arbitrary order, one after the
|
| 649 |
other, satisfies the requirements of parallel forward progress for these
|
|
|
|
| 651 |
|
| 652 |
For a thread of execution providing *weakly parallel forward progress
|
| 653 |
guarantees*, the implementation does not ensure that the thread will
|
| 654 |
eventually make progress.
|
| 655 |
|
| 656 |
+
[*Note 7*: Threads of execution providing weakly parallel forward
|
| 657 |
progress guarantees cannot be expected to make progress regardless of
|
| 658 |
whether other threads make progress or not; however, blocking with
|
| 659 |
forward progress guarantee delegation, as defined below, can be used to
|
| 660 |
ensure that such threads of execution make progress
|
| 661 |
eventually. — *end note*]
|
| 662 |
|
| 663 |
Concurrent forward progress guarantees are stronger than parallel
|
| 664 |
forward progress guarantees, which in turn are stronger than weakly
|
| 665 |
parallel forward progress guarantees.
|
| 666 |
|
| 667 |
+
[*Note 8*: For example, some kinds of synchronization between threads
|
| 668 |
+
of execution might only make progress if the respective threads of
|
| 669 |
execution provide parallel forward progress guarantees, but will fail to
|
| 670 |
make progress under weakly parallel guarantees. — *end note*]
|
| 671 |
|
| 672 |
When a thread of execution P is specified to *block with forward
|
| 673 |
progress guarantee delegation* on the completion of a set S of threads
|
| 674 |
of execution, then throughout the whole time of P being blocked on S,
|
| 675 |
the implementation shall ensure that the forward progress guarantees
|
| 676 |
provided by at least one thread of execution in S is at least as strong
|
| 677 |
as P’s forward progress guarantees.
|
| 678 |
|
| 679 |
+
[*Note 9*: It is unspecified which thread or threads of execution in S
|
| 680 |
are chosen and for which number of execution steps. The strengthening is
|
| 681 |
not permanent and not necessarily in place for the rest of the lifetime
|
| 682 |
of the affected thread of execution. As long as P is blocked, the
|
| 683 |
implementation has to eventually select and potentially strengthen a
|
| 684 |
thread of execution in S. — *end note*]
|
| 685 |
|
| 686 |
Once a thread of execution in S terminates, it is removed from S. Once S
|
| 687 |
is empty, P is unblocked.
|
| 688 |
|
| 689 |
+
[*Note 10*: A thread of execution B thus can temporarily provide an
|
| 690 |
effectively stronger forward progress guarantee for a certain amount of
|
| 691 |
time, due to a second thread of execution A being blocked on it with
|
| 692 |
forward progress guarantee delegation. In turn, if B then blocks with
|
| 693 |
+
forward progress guarantee delegation on C, this can also temporarily
|
| 694 |
provide a stronger forward progress guarantee to C. — *end note*]
|
| 695 |
|
| 696 |
+
[*Note 11*: If all threads of execution in S finish executing (e.g.,
|
| 697 |
they terminate and do not use blocking synchronization incorrectly),
|
| 698 |
then P’s execution of the operation that blocks with forward progress
|
| 699 |
guarantee delegation will not result in P’s progress guarantee being
|
| 700 |
effectively weakened. — *end note*]
|
| 701 |
|
| 702 |
+
[*Note 12*: This does not remove any constraints regarding blocking
|
| 703 |
synchronization for threads of execution providing parallel or weakly
|
| 704 |
parallel forward progress guarantees because the implementation is not
|
| 705 |
required to strengthen a particular thread of execution whose too-weak
|
| 706 |
progress guarantee is preventing overall progress. — *end note*]
|
| 707 |
|
|
|
|
| 711 |
|
| 712 |
### Start and termination <a id="basic.start">[[basic.start]]</a>
|
| 713 |
|
| 714 |
#### `main` function <a id="basic.start.main">[[basic.start.main]]</a>
|
| 715 |
|
| 716 |
+
A program shall contain exactly one function called `main` that belongs
|
| 717 |
+
to the global scope. Executing a program starts a main thread of
|
| 718 |
+
execution [[intro.multithread]], [[thread.threads]] in which the `main`
|
| 719 |
+
function is invoked. It is *implementation-defined* whether a program in
|
| 720 |
+
a freestanding environment is required to define a `main` function.
|
|
|
|
|
|
|
| 721 |
|
| 722 |
[*Note 1*: In a freestanding environment, startup and termination is
|
| 723 |
*implementation-defined*; startup contains the execution of constructors
|
| 724 |
+
for non-local objects with static storage duration; termination contains
|
| 725 |
+
the execution of destructors for objects with static storage
|
| 726 |
duration. — *end note*]
|
| 727 |
|
| 728 |
+
An implementation shall not predefine the `main` function. Its type
|
| 729 |
+
shall have C++ language linkage and it shall have a declared return type
|
| 730 |
+
of type `int`, but otherwise its type is *implementation-defined*. An
|
| 731 |
+
implementation shall allow both
|
| 732 |
|
| 733 |
- a function of `()` returning `int` and
|
| 734 |
- a function of `(int`, pointer to pointer to `char)` returning `int`
|
| 735 |
|
| 736 |
as the type of `main` [[dcl.fct]]. In the latter form, for purposes of
|
|
|
|
| 743 |
[[multibyte.strings]] and `argv[0]` shall be the pointer to the initial
|
| 744 |
character of a NTMBS that represents the name used to invoke the program
|
| 745 |
or `""`. The value of `argc` shall be non-negative. The value of
|
| 746 |
`argv[argc]` shall be 0.
|
| 747 |
|
| 748 |
+
*Recommended practice:* Any further (optional) parameters should be
|
| 749 |
+
added after `argv`.
|
| 750 |
|
| 751 |
The function `main` shall not be used within a program. The linkage
|
| 752 |
[[basic.link]] of `main` is *implementation-defined*. A program that
|
| 753 |
defines `main` as deleted or that declares `main` to be `inline`,
|
| 754 |
+
`static`, `constexpr`, or `consteval` is ill-formed. The function `main`
|
| 755 |
+
shall not be a coroutine [[dcl.fct.def.coroutine]]. The `main` function
|
| 756 |
+
shall not be declared with a *linkage-specification* [[dcl.link]]. A
|
| 757 |
+
program that declares
|
| 758 |
+
|
| 759 |
+
- a variable `main` that belongs to the global scope, or
|
| 760 |
+
- a function `main` that belongs to the global scope and is attached to
|
| 761 |
+
a named module, or
|
| 762 |
+
- a function template `main` that belongs to the global scope, or
|
| 763 |
+
- an entity named `main` with C language linkage (in any namespace)
|
| 764 |
+
|
| 765 |
+
is ill-formed. The name `main` is not otherwise reserved.
|
| 766 |
|
| 767 |
[*Example 1*: Member functions, classes, and enumerations can be called
|
| 768 |
`main`, as can entities in other namespaces. — *end example*]
|
| 769 |
|
| 770 |
Terminating the program without leaving the current block (e.g., by
|
| 771 |
calling the function `std::exit(int)` [[support.start.term]]) does not
|
| 772 |
destroy any objects with automatic storage duration [[class.dtor]]. If
|
| 773 |
+
`std::exit` is invoked during the destruction of an object with static
|
| 774 |
+
or thread storage duration, the program has undefined behavior.
|
|
|
|
| 775 |
|
| 776 |
A `return` statement [[stmt.return]] in `main` has the effect of leaving
|
| 777 |
the main function (destroying any objects with automatic storage
|
| 778 |
duration) and calling `std::exit` with the return value as the argument.
|
| 779 |
If control flows off the end of the *compound-statement* of `main`, the
|
|
|
|
| 791 |
with static or thread storage duration is constant-initialized
|
| 792 |
[[expr.const]]. If constant initialization is not performed, a variable
|
| 793 |
with static storage duration [[basic.stc.static]] or thread storage
|
| 794 |
duration [[basic.stc.thread]] is zero-initialized [[dcl.init]].
|
| 795 |
Together, zero-initialization and constant initialization are called
|
| 796 |
+
*static initialization*; all other initialization is
|
| 797 |
+
*dynamic initialization*. All static initialization strongly happens
|
| 798 |
+
before [[intro.races]] any dynamic initialization.
|
| 799 |
|
| 800 |
+
[*Note 1*: The dynamic initialization of non-block variables is
|
| 801 |
+
described in [[basic.start.dynamic]]; that of static block variables is
|
| 802 |
described in [[stmt.dcl]]. — *end note*]
|
| 803 |
|
| 804 |
An implementation is permitted to perform the initialization of a
|
| 805 |
variable with static or thread storage duration as a static
|
| 806 |
initialization even if such initialization is not required to be done
|
|
|
|
| 815 |
statically were initialized dynamically.
|
| 816 |
|
| 817 |
[*Note 2*:
|
| 818 |
|
| 819 |
As a consequence, if the initialization of an object `obj1` refers to an
|
| 820 |
+
object `obj2` potentially requiring dynamic initialization and defined
|
| 821 |
+
later in the same translation unit, it is unspecified whether the value
|
| 822 |
+
of `obj2` used will be the value of the fully initialized `obj2`
|
| 823 |
+
(because `obj2` was statically initialized) or will be the value of
|
| 824 |
+
`obj2` merely zero-initialized. For example,
|
| 825 |
|
| 826 |
``` cpp
|
| 827 |
inline double fd() { return 1.0; }
|
| 828 |
extern double d1;
|
| 829 |
double d2 = d1; // unspecified:
|
| 830 |
+
// either statically initialized to 0.0 or
|
| 831 |
// dynamically initialized to 0.0 if d1 is
|
| 832 |
// dynamically initialized, or 1.0 otherwise
|
| 833 |
+
double d1 = fd(); // either initialized statically or dynamically to 1.0
|
| 834 |
```
|
| 835 |
|
| 836 |
— *end note*]
|
| 837 |
|
| 838 |
+
#### Dynamic initialization of non-block variables <a id="basic.start.dynamic">[[basic.start.dynamic]]</a>
|
| 839 |
|
| 840 |
+
Dynamic initialization of a non-block variable with static storage
|
| 841 |
duration is unordered if the variable is an implicitly or explicitly
|
| 842 |
instantiated specialization, is partially-ordered if the variable is an
|
| 843 |
inline variable that is not an implicitly or explicitly instantiated
|
| 844 |
specialization, and otherwise is ordered.
|
| 845 |
|
| 846 |
+
[*Note 1*: A non-inline explicit specialization of a templated variable
|
| 847 |
+
has ordered initialization. — *end note*]
|
|
|
|
| 848 |
|
| 849 |
A declaration `D` is *appearance-ordered* before a declaration `E` if
|
| 850 |
|
| 851 |
- `D` appears in the same translation unit as `E`, or
|
| 852 |
- the translation unit containing `E` has an interface dependency on the
|
| 853 |
translation unit containing `D`,
|
| 854 |
|
| 855 |
in either case prior to `E`.
|
| 856 |
|
| 857 |
+
Dynamic initialization of non-block variables `V` and `W` with static
|
| 858 |
storage duration are ordered as follows:
|
| 859 |
|
| 860 |
- If `V` and `W` have ordered initialization and the definition of `V`
|
| 861 |
is appearance-ordered before the definition of `W`, or if `V` has
|
| 862 |
partially-ordered initialization, `W` does not have unordered
|
|
|
|
| 878 |
sequenced.
|
| 879 |
|
| 880 |
[*Note 2*: This definition permits initialization of a sequence of
|
| 881 |
ordered variables concurrently with another sequence. — *end note*]
|
| 882 |
|
| 883 |
+
A *non-initialization odr-use* is an odr-use [[term.odr.use]] not caused
|
| 884 |
+
directly or indirectly by the initialization of a non-block static or
|
| 885 |
+
thread storage duration variable.
|
| 886 |
|
| 887 |
It is *implementation-defined* whether the dynamic initialization of a
|
| 888 |
+
non-block non-inline variable with static storage duration is sequenced
|
| 889 |
before the first statement of `main` or is deferred. If it is deferred,
|
| 890 |
it strongly happens before any non-initialization odr-use of any
|
| 891 |
non-inline function or non-inline variable defined in the same
|
| 892 |
+
translation unit as the variable to be initialized.[^25]
|
|
|
|
|
|
|
| 893 |
|
| 894 |
+
It is *implementation-defined* in which threads and at which points in
|
| 895 |
+
the program such deferred dynamic initialization occurs.
|
| 896 |
+
|
| 897 |
+
*Recommended practice:* An implementation should choose such points in a
|
| 898 |
+
way that allows the programmer to avoid deadlocks.
|
| 899 |
|
| 900 |
[*Example 1*:
|
| 901 |
|
| 902 |
``` cpp
|
| 903 |
// - File 1 -
|
|
|
|
| 934 |
to its use in `A::A`.
|
| 935 |
|
| 936 |
— *end example*]
|
| 937 |
|
| 938 |
It is *implementation-defined* whether the dynamic initialization of a
|
| 939 |
+
non-block inline variable with static storage duration is sequenced
|
| 940 |
before the first statement of `main` or is deferred. If it is deferred,
|
| 941 |
it strongly happens before any non-initialization odr-use of that
|
| 942 |
variable. It is *implementation-defined* in which threads and at which
|
| 943 |
points in the program such deferred dynamic initialization occurs.
|
| 944 |
|
| 945 |
It is *implementation-defined* whether the dynamic initialization of a
|
| 946 |
+
non-block non-inline variable with thread storage duration is sequenced
|
| 947 |
before the first statement of the initial function of a thread or is
|
| 948 |
deferred. If it is deferred, the initialization associated with the
|
| 949 |
entity for thread *t* is sequenced before the first non-initialization
|
| 950 |
odr-use by *t* of any non-inline variable with thread storage duration
|
| 951 |
defined in the same translation unit as the variable to be initialized.
|
| 952 |
It is *implementation-defined* in which threads and at which points in
|
| 953 |
the program such deferred dynamic initialization occurs.
|
| 954 |
|
| 955 |
+
If the initialization of a non-block variable with static or thread
|
| 956 |
storage duration exits via an exception, the function `std::terminate`
|
| 957 |
is called [[except.terminate]].
|
| 958 |
|
| 959 |
#### Termination <a id="basic.start.term">[[basic.start.term]]</a>
|
| 960 |
|
|
|
|
| 981 |
storage duration is sequenced before that of another, the completion of
|
| 982 |
the destructor of the second is sequenced before the initiation of the
|
| 983 |
destructor of the first. If an object is initialized statically, the
|
| 984 |
object is destroyed in the same order as if the object was dynamically
|
| 985 |
initialized. For an object of array or class type, all subobjects of
|
| 986 |
+
that object are destroyed before any block variable with static storage
|
| 987 |
+
duration initialized during the construction of the subobjects is
|
| 988 |
+
destroyed. If the destruction of an object with static or thread storage
|
| 989 |
+
duration exits via an exception, the function `std::terminate` is called
|
| 990 |
+
[[except.terminate]].
|
| 991 |
|
| 992 |
+
If a function contains a block variable of static or thread storage
|
| 993 |
duration that has been destroyed and the function is called during the
|
| 994 |
destruction of an object with static or thread storage duration, the
|
| 995 |
program has undefined behavior if the flow of control passes through the
|
| 996 |
+
definition of the previously destroyed block variable.
|
| 997 |
+
|
| 998 |
+
[*Note 2*: Likewise, the behavior is undefined if the block variable is
|
| 999 |
+
used indirectly (e.g., through a pointer) after its
|
| 1000 |
+
destruction. — *end note*]
|
| 1001 |
|
| 1002 |
If the completion of the initialization of an object with static storage
|
| 1003 |
duration strongly happens before a call to `std::atexit` (see
|
| 1004 |
`<cstdlib>`, [[support.start.term]]), the call to the function passed to
|
| 1005 |
`std::atexit` is sequenced before the call to the destructor for the
|
|
|
|
| 1016 |
within signal handlers [[support.runtime]] that does not happen before
|
| 1017 |
[[intro.multithread]] completion of destruction of objects with static
|
| 1018 |
storage duration and execution of `std::atexit` registered functions
|
| 1019 |
[[support.start.term]], the program has undefined behavior.
|
| 1020 |
|
| 1021 |
+
[*Note 3*: If there is a use of an object with static storage duration
|
| 1022 |
that does not happen before the object’s destruction, the program has
|
| 1023 |
undefined behavior. Terminating every thread before a call to
|
| 1024 |
`std::exit` or the exit from `main` is sufficient, but not necessary, to
|
| 1025 |
satisfy these requirements. These requirements permit thread managers as
|
| 1026 |
static-storage-duration objects. — *end note*]
|
|
|
|
| 1028 |
Calling the function `std::abort()` declared in `<cstdlib>` terminates
|
| 1029 |
the program without executing any destructors and without calling the
|
| 1030 |
functions passed to `std::atexit()` or `std::at_quick_exit()`.
|
| 1031 |
|
| 1032 |
<!-- Link reference definitions -->
|
| 1033 |
+
[allocator.members]: mem.md#allocator.members
|
| 1034 |
+
[allocator.traits.members]: mem.md#allocator.traits.members
|
| 1035 |
+
[atomics]: thread.md#atomics
|
| 1036 |
+
[atomics.flag]: thread.md#atomics.flag
|
| 1037 |
+
[atomics.lockfree]: thread.md#atomics.lockfree
|
| 1038 |
+
[atomics.order]: thread.md#atomics.order
|
| 1039 |
[bad.alloc]: support.md#bad.alloc
|
| 1040 |
[basic]: #basic
|
| 1041 |
[basic.align]: #basic.align
|
| 1042 |
[basic.compound]: #basic.compound
|
| 1043 |
[basic.def]: #basic.def
|
| 1044 |
[basic.def.odr]: #basic.def.odr
|
| 1045 |
[basic.exec]: #basic.exec
|
| 1046 |
+
[basic.extended.fp]: #basic.extended.fp
|
| 1047 |
[basic.fundamental]: #basic.fundamental
|
| 1048 |
[basic.fundamental.width]: #basic.fundamental.width
|
|
|
|
| 1049 |
[basic.indet]: #basic.indet
|
| 1050 |
[basic.life]: #basic.life
|
| 1051 |
[basic.link]: #basic.link
|
| 1052 |
[basic.lookup]: #basic.lookup
|
| 1053 |
[basic.lookup.argdep]: #basic.lookup.argdep
|
|
|
|
| 1054 |
[basic.lookup.elab]: #basic.lookup.elab
|
| 1055 |
+
[basic.lookup.general]: #basic.lookup.general
|
| 1056 |
[basic.lookup.qual]: #basic.lookup.qual
|
| 1057 |
+
[basic.lookup.qual.general]: #basic.lookup.qual.general
|
| 1058 |
[basic.lookup.udir]: #basic.lookup.udir
|
| 1059 |
[basic.lookup.unqual]: #basic.lookup.unqual
|
| 1060 |
[basic.lval]: expr.md#basic.lval
|
| 1061 |
[basic.memobj]: #basic.memobj
|
| 1062 |
[basic.namespace]: dcl.md#basic.namespace
|
| 1063 |
[basic.pre]: #basic.pre
|
| 1064 |
[basic.scope]: #basic.scope
|
| 1065 |
[basic.scope.block]: #basic.scope.block
|
| 1066 |
[basic.scope.class]: #basic.scope.class
|
|
|
|
| 1067 |
[basic.scope.enum]: #basic.scope.enum
|
| 1068 |
+
[basic.scope.lambda]: #basic.scope.lambda
|
| 1069 |
[basic.scope.namespace]: #basic.scope.namespace
|
| 1070 |
[basic.scope.param]: #basic.scope.param
|
| 1071 |
[basic.scope.pdecl]: #basic.scope.pdecl
|
| 1072 |
+
[basic.scope.scope]: #basic.scope.scope
|
| 1073 |
[basic.scope.temp]: #basic.scope.temp
|
| 1074 |
[basic.start]: #basic.start
|
| 1075 |
[basic.start.dynamic]: #basic.start.dynamic
|
| 1076 |
[basic.start.main]: #basic.start.main
|
| 1077 |
[basic.start.static]: #basic.start.static
|
|
|
|
| 1079 |
[basic.stc]: #basic.stc
|
| 1080 |
[basic.stc.auto]: #basic.stc.auto
|
| 1081 |
[basic.stc.dynamic]: #basic.stc.dynamic
|
| 1082 |
[basic.stc.dynamic.allocation]: #basic.stc.dynamic.allocation
|
| 1083 |
[basic.stc.dynamic.deallocation]: #basic.stc.dynamic.deallocation
|
| 1084 |
+
[basic.stc.dynamic.general]: #basic.stc.dynamic.general
|
| 1085 |
+
[basic.stc.general]: #basic.stc.general
|
| 1086 |
[basic.stc.inherit]: #basic.stc.inherit
|
| 1087 |
[basic.stc.static]: #basic.stc.static
|
| 1088 |
[basic.stc.thread]: #basic.stc.thread
|
| 1089 |
[basic.type.qualifier]: #basic.type.qualifier
|
| 1090 |
[basic.type.qualifier.rel]: #basic.type.qualifier.rel
|
| 1091 |
[basic.types]: #basic.types
|
| 1092 |
+
[basic.types.general]: #basic.types.general
|
| 1093 |
+
[bit.cast]: utilities.md#bit.cast
|
| 1094 |
+
[c.malloc]: mem.md#c.malloc
|
| 1095 |
[class]: class.md#class
|
| 1096 |
[class.abstract]: class.md#class.abstract
|
| 1097 |
[class.access]: class.md#class.access
|
| 1098 |
+
[class.access.base]: class.md#class.access.base
|
| 1099 |
[class.base.init]: class.md#class.base.init
|
| 1100 |
[class.bit]: class.md#class.bit
|
| 1101 |
[class.cdtor]: class.md#class.cdtor
|
| 1102 |
[class.conv.fct]: class.md#class.conv.fct
|
| 1103 |
[class.copy.assign]: class.md#class.copy.assign
|
|
|
|
| 1106 |
[class.default.ctor]: class.md#class.default.ctor
|
| 1107 |
[class.derived]: class.md#class.derived
|
| 1108 |
[class.dtor]: class.md#class.dtor
|
| 1109 |
[class.free]: class.md#class.free
|
| 1110 |
[class.friend]: class.md#class.friend
|
|
|
|
| 1111 |
[class.mem]: class.md#class.mem
|
| 1112 |
+
[class.member.lookup]: #class.member.lookup
|
| 1113 |
[class.mfct]: class.md#class.mfct
|
| 1114 |
+
[class.mfct.non.static]: class.md#class.mfct.non.static
|
| 1115 |
[class.name]: class.md#class.name
|
|
|
|
| 1116 |
[class.pre]: class.md#class.pre
|
| 1117 |
[class.prop]: class.md#class.prop
|
| 1118 |
[class.qual]: #class.qual
|
| 1119 |
[class.spaceship]: class.md#class.spaceship
|
| 1120 |
[class.static]: class.md#class.static
|
| 1121 |
[class.static.data]: class.md#class.static.data
|
| 1122 |
[class.temporary]: #class.temporary
|
|
|
|
| 1123 |
[class.union]: class.md#class.union
|
| 1124 |
+
[class.union.anon]: class.md#class.union.anon
|
| 1125 |
[class.virtual]: class.md#class.virtual
|
| 1126 |
[conv]: expr.md#conv
|
| 1127 |
[conv.array]: expr.md#conv.array
|
| 1128 |
[conv.func]: expr.md#conv.func
|
| 1129 |
[conv.integral]: expr.md#conv.integral
|
|
|
|
| 1151 |
[dcl.fct.default]: dcl.md#dcl.fct.default
|
| 1152 |
[dcl.init]: dcl.md#dcl.init
|
| 1153 |
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 1154 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 1155 |
[dcl.init.ref]: dcl.md#dcl.init.ref
|
|
|
|
| 1156 |
[dcl.link]: dcl.md#dcl.link
|
| 1157 |
[dcl.meaning]: dcl.md#dcl.meaning
|
| 1158 |
[dcl.mptr]: dcl.md#dcl.mptr
|
| 1159 |
[dcl.name]: dcl.md#dcl.name
|
| 1160 |
[dcl.pre]: dcl.md#dcl.pre
|
|
|
|
| 1162 |
[dcl.ref]: dcl.md#dcl.ref
|
| 1163 |
[dcl.spec]: dcl.md#dcl.spec
|
| 1164 |
[dcl.spec.auto]: dcl.md#dcl.spec.auto
|
| 1165 |
[dcl.stc]: dcl.md#dcl.stc
|
| 1166 |
[dcl.struct.bind]: dcl.md#dcl.struct.bind
|
| 1167 |
+
[dcl.type.decltype]: dcl.md#dcl.type.decltype
|
| 1168 |
[dcl.type.elab]: dcl.md#dcl.type.elab
|
| 1169 |
[dcl.typedef]: dcl.md#dcl.typedef
|
| 1170 |
[defns.block]: intro.md#defns.block
|
|
|
|
|
|
|
| 1171 |
[depr.local]: future.md#depr.local
|
| 1172 |
[depr.static.constexpr]: future.md#depr.static.constexpr
|
| 1173 |
[diff.cpp11.basic]: compatibility.md#diff.cpp11.basic
|
| 1174 |
[enum.udecl]: dcl.md#enum.udecl
|
| 1175 |
[except.handle]: except.md#except.handle
|
| 1176 |
[except.pre]: except.md#except.pre
|
| 1177 |
[except.spec]: except.md#except.spec
|
| 1178 |
[except.terminate]: except.md#except.terminate
|
| 1179 |
[except.throw]: except.md#except.throw
|
|
|
|
| 1180 |
[expr.add]: expr.md#expr.add
|
| 1181 |
[expr.alignof]: expr.md#expr.alignof
|
| 1182 |
[expr.arith.conv]: expr.md#expr.arith.conv
|
| 1183 |
[expr.ass]: expr.md#expr.ass
|
| 1184 |
[expr.await]: expr.md#expr.await
|
| 1185 |
[expr.call]: expr.md#expr.call
|
| 1186 |
[expr.cast]: expr.md#expr.cast
|
| 1187 |
[expr.comma]: expr.md#expr.comma
|
|
|
|
| 1188 |
[expr.cond]: expr.md#expr.cond
|
| 1189 |
[expr.const]: expr.md#expr.const
|
| 1190 |
[expr.const.cast]: expr.md#expr.const.cast
|
| 1191 |
[expr.context]: expr.md#expr.context
|
| 1192 |
[expr.delete]: expr.md#expr.delete
|
|
|
|
| 1196 |
[expr.log.or]: expr.md#expr.log.or
|
| 1197 |
[expr.mptr.oper]: expr.md#expr.mptr.oper
|
| 1198 |
[expr.new]: expr.md#expr.new
|
| 1199 |
[expr.pre]: expr.md#expr.pre
|
| 1200 |
[expr.prim.id]: expr.md#expr.prim.id
|
|
|
|
| 1201 |
[expr.prim.id.qual]: expr.md#expr.prim.id.qual
|
| 1202 |
+
[expr.prim.id.unqual]: expr.md#expr.prim.id.unqual
|
| 1203 |
[expr.prim.lambda]: expr.md#expr.prim.lambda
|
| 1204 |
[expr.prim.lambda.capture]: expr.md#expr.prim.lambda.capture
|
| 1205 |
[expr.prim.lambda.closure]: expr.md#expr.prim.lambda.closure
|
| 1206 |
[expr.prim.this]: expr.md#expr.prim.this
|
| 1207 |
[expr.prop]: expr.md#expr.prop
|
|
|
|
| 1217 |
[get.new.handler]: support.md#get.new.handler
|
| 1218 |
[headers]: library.md#headers
|
| 1219 |
[intro.execution]: #intro.execution
|
| 1220 |
[intro.memory]: #intro.memory
|
| 1221 |
[intro.multithread]: #intro.multithread
|
| 1222 |
+
[intro.multithread.general]: #intro.multithread.general
|
| 1223 |
[intro.object]: #intro.object
|
| 1224 |
[intro.progress]: #intro.progress
|
| 1225 |
[intro.races]: #intro.races
|
| 1226 |
[lex.charset]: lex.md#lex.charset
|
| 1227 |
+
[lex.fcon]: lex.md#lex.fcon
|
| 1228 |
[lex.name]: lex.md#lex.name
|
| 1229 |
[lex.separate]: lex.md#lex.separate
|
|
|
|
|
|
|
| 1230 |
[module.context]: module.md#module.context
|
| 1231 |
[module.global.frag]: module.md#module.global.frag
|
|
|
|
| 1232 |
[module.interface]: module.md#module.interface
|
| 1233 |
[module.reach]: module.md#module.reach
|
| 1234 |
[module.unit]: module.md#module.unit
|
| 1235 |
[multibyte.strings]: library.md#multibyte.strings
|
| 1236 |
[namespace.def]: dcl.md#namespace.def
|
|
|
|
| 1237 |
[namespace.qual]: #namespace.qual
|
| 1238 |
[namespace.udecl]: dcl.md#namespace.udecl
|
| 1239 |
[namespace.udir]: dcl.md#namespace.udir
|
| 1240 |
+
[namespace.unnamed]: dcl.md#namespace.unnamed
|
| 1241 |
[new.delete]: support.md#new.delete
|
| 1242 |
[new.delete.array]: support.md#new.delete.array
|
| 1243 |
[new.delete.placement]: support.md#new.delete.placement
|
| 1244 |
[new.delete.single]: support.md#new.delete.single
|
| 1245 |
[new.handler]: support.md#new.handler
|
| 1246 |
+
[new.syn]: support.md#new.syn
|
| 1247 |
+
[obj.lifetime]: mem.md#obj.lifetime
|
| 1248 |
[over]: over.md#over
|
| 1249 |
[over.literal]: over.md#over.literal
|
| 1250 |
[over.match]: over.md#over.match
|
| 1251 |
+
[over.match.funcs]: over.md#over.match.funcs
|
| 1252 |
[over.oper]: over.md#over.oper
|
| 1253 |
[over.over]: over.md#over.over
|
| 1254 |
+
[ptr.align]: mem.md#ptr.align
|
| 1255 |
[ptr.launder]: support.md#ptr.launder
|
| 1256 |
[replacement.functions]: library.md#replacement.functions
|
| 1257 |
[special]: class.md#special
|
| 1258 |
+
[std.modules]: library.md#std.modules
|
| 1259 |
+
[stdfloat.syn]: support.md#stdfloat.syn
|
| 1260 |
[stmt.block]: stmt.md#stmt.block
|
| 1261 |
[stmt.dcl]: stmt.md#stmt.dcl
|
| 1262 |
[stmt.expr]: stmt.md#stmt.expr
|
|
|
|
| 1263 |
[stmt.if]: stmt.md#stmt.if
|
| 1264 |
+
[stmt.iter]: stmt.md#stmt.iter
|
| 1265 |
+
[stmt.pre]: stmt.md#stmt.pre
|
| 1266 |
[stmt.ranged]: stmt.md#stmt.ranged
|
| 1267 |
[stmt.return]: stmt.md#stmt.return
|
| 1268 |
+
[stmt.select]: stmt.md#stmt.select
|
| 1269 |
[support.dynamic]: support.md#support.dynamic
|
|
|
|
| 1270 |
[support.runtime]: support.md#support.runtime
|
| 1271 |
[support.start.term]: support.md#support.start.term
|
| 1272 |
[support.types]: support.md#support.types
|
| 1273 |
+
[temp.concept]: temp.md#temp.concept
|
| 1274 |
[temp.deduct.guide]: temp.md#temp.deduct.guide
|
| 1275 |
[temp.dep]: temp.md#temp.dep
|
| 1276 |
[temp.dep.candidate]: temp.md#temp.dep.candidate
|
| 1277 |
+
[temp.dep.constexpr]: temp.md#temp.dep.constexpr
|
| 1278 |
+
[temp.dep.type]: temp.md#temp.dep.type
|
| 1279 |
[temp.expl.spec]: temp.md#temp.expl.spec
|
| 1280 |
[temp.explicit]: temp.md#temp.explicit
|
| 1281 |
+
[temp.friend]: temp.md#temp.friend
|
| 1282 |
[temp.local]: temp.md#temp.local
|
| 1283 |
[temp.names]: temp.md#temp.names
|
|
|
|
| 1284 |
[temp.over]: temp.md#temp.over
|
| 1285 |
+
[temp.over.link]: temp.md#temp.over.link
|
| 1286 |
[temp.param]: temp.md#temp.param
|
| 1287 |
[temp.point]: temp.md#temp.point
|
| 1288 |
[temp.pre]: temp.md#temp.pre
|
| 1289 |
[temp.res]: temp.md#temp.res
|
| 1290 |
[temp.spec]: temp.md#temp.spec
|
| 1291 |
+
[temp.spec.partial]: temp.md#temp.spec.partial
|
| 1292 |
[temp.type]: temp.md#temp.type
|
| 1293 |
+
[term.incomplete.type]: #term.incomplete.type
|
| 1294 |
+
[term.odr.use]: #term.odr.use
|
| 1295 |
+
[term.unevaluated.operand]: expr.md#term.unevaluated.operand
|
| 1296 |
[thread]: thread.md#thread
|
| 1297 |
[thread.jthread.class]: thread.md#thread.jthread.class
|
| 1298 |
[thread.thread.class]: thread.md#thread.thread.class
|
| 1299 |
[thread.threads]: thread.md#thread.threads
|
|
|
|
| 1300 |
|
| 1301 |
[^1]: Appearing inside the brace-enclosed *declaration-seq* in a
|
| 1302 |
*linkage-specification* does not affect whether a declaration is a
|
| 1303 |
definition.
|
| 1304 |
|
| 1305 |
[^2]: An implementation is not required to call allocation and
|
| 1306 |
deallocation functions from constructors or destructors; however,
|
| 1307 |
this is a permissible implementation technique.
|
| 1308 |
|
| 1309 |
+
[^3]: An implicit object parameter [[over.match.funcs]] is not part of
|
| 1310 |
+
the parameter-type-list.
|
|
|
|
| 1311 |
|
| 1312 |
+
[^4]: Lookups in which function names are ignored include names
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1313 |
appearing in a *nested-name-specifier*, an
|
| 1314 |
*elaborated-type-specifier*, or a *base-specifier*.
|
| 1315 |
|
| 1316 |
+
[^5]: Unicode® is a registered trademark of Unicode, Inc. This
|
| 1317 |
+
information is given for the convenience of users of this document
|
| 1318 |
+
and does not constitute an endorsement by ISO or IEC of this
|
| 1319 |
+
product.
|
| 1320 |
+
|
| 1321 |
+
[^6]: The number of bits in a byte is reported by the macro `CHAR_BIT`
|
| 1322 |
in the header `<climits>`.
|
| 1323 |
|
| 1324 |
+
[^7]: Under the “as-if” rule an implementation is allowed to store two
|
| 1325 |
objects at the same machine address or not store an object at all if
|
| 1326 |
the program cannot observe the difference [[intro.execution]].
|
| 1327 |
|
| 1328 |
+
[^8]: For example, before the dynamic initialization of an object with
|
| 1329 |
+
static storage duration [[basic.start.dynamic]].
|
| 1330 |
|
| 1331 |
+
[^9]: That is, an object for which a destructor will be called
|
| 1332 |
implicitly—upon exit from the block for an object with automatic
|
| 1333 |
storage duration, upon exit from the thread for an object with
|
| 1334 |
thread storage duration, or upon exit from the program for an object
|
| 1335 |
with static storage duration.
|
| 1336 |
|
| 1337 |
+
[^10]: Some implementations might define that copying an invalid pointer
|
| 1338 |
value causes a system-generated runtime fault.
|
| 1339 |
|
| 1340 |
+
[^11]: The intent is to have `operator new()` implementable by calling
|
| 1341 |
`std::malloc()` or `std::calloc()`, so the rules are substantially
|
| 1342 |
the same. C++ differs from C in requiring a zero request to return a
|
| 1343 |
non-null pointer.
|
| 1344 |
|
| 1345 |
+
[^12]: The global `operator delete(void*, std::size_t)` precludes use of
|
| 1346 |
an allocation function `void operator new(std::size_t, std::size_t)`
|
| 1347 |
+
as a placement allocation function [[diff.cpp11.basic]].
|
| 1348 |
|
| 1349 |
+
[^13]: The same rules apply to initialization of an `initializer_list`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1350 |
object [[dcl.init.list]] with its underlying temporary array.
|
| 1351 |
|
| 1352 |
+
[^14]: By using, for example, the library functions [[headers]]
|
| 1353 |
`std::memcpy` or `std::memmove`.
|
| 1354 |
|
| 1355 |
+
[^15]: By using, for example, the library functions [[headers]]
|
| 1356 |
`std::memcpy` or `std::memmove`.
|
| 1357 |
|
| 1358 |
+
[^16]: The intent is that the memory model of C++ is compatible with
|
| 1359 |
that of ISO/IEC 9899 Programming Language C.
|
| 1360 |
|
| 1361 |
+
[^17]: The size and layout of an instance of an incompletely-defined
|
| 1362 |
object type is unknown.
|
| 1363 |
|
| 1364 |
+
[^18]: This is also known as two’s complement representation.
|
| 1365 |
|
| 1366 |
+
[^19]: Static class members are objects or functions, and pointers to
|
| 1367 |
them are ordinary pointers to objects or functions.
|
| 1368 |
|
| 1369 |
+
[^20]: For an object that is not within its lifetime, this is the first
|
| 1370 |
byte in memory that it will occupy or used to occupy.
|
| 1371 |
|
| 1372 |
+
[^21]: The same representation and alignment requirements are meant to
|
| 1373 |
imply interchangeability as arguments to functions, return values
|
| 1374 |
from functions, and non-static data members of unions.
|
| 1375 |
|
| 1376 |
+
[^22]: As specified in [[class.temporary]], after a full-expression is
|
| 1377 |
evaluated, a sequence of zero or more invocations of destructor
|
| 1378 |
functions for temporary objects takes place, usually in reverse
|
| 1379 |
order of the construction of each temporary object.
|
| 1380 |
|
| 1381 |
+
[^23]: In other words, function executions do not interleave with each
|
| 1382 |
other.
|
| 1383 |
|
| 1384 |
+
[^24]: An object with automatic or thread storage duration [[basic.stc]]
|
| 1385 |
is associated with one specific thread, and can be accessed by a
|
| 1386 |
different thread only indirectly through a pointer or reference
|
| 1387 |
[[basic.compound]].
|
| 1388 |
|
| 1389 |
+
[^25]: A non-block variable with static storage duration having
|
| 1390 |
initialization with side effects is initialized in this case, even
|
| 1391 |
+
if it is not itself odr-used [[term.odr.use]], [[basic.stc.static]].
|
|
|