tmp/tmp4xmygu97/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Static initialization <a id="basic.start.static">[[basic.start.static]]</a>
|
| 2 |
+
|
| 3 |
+
Variables with static storage duration are initialized as a consequence
|
| 4 |
+
of program initiation. Variables with thread storage duration are
|
| 5 |
+
initialized as a consequence of thread execution. Within each of these
|
| 6 |
+
phases of initiation, initialization occurs as follows.
|
| 7 |
+
|
| 8 |
+
A *constant initializer* for a variable or temporary object `o` is an
|
| 9 |
+
initializer whose full-expression is a constant expression, except that
|
| 10 |
+
if `o` is an object, such an initializer may also invoke constexpr
|
| 11 |
+
constructors for `o` and its subobjects even if those objects are of
|
| 12 |
+
non-literal class types.
|
| 13 |
+
|
| 14 |
+
[*Note 1*: Such a class may have a non-trivial
|
| 15 |
+
destructor. — *end note*]
|
| 16 |
+
|
| 17 |
+
*Constant initialization* is performed if a variable or temporary object
|
| 18 |
+
with static or thread storage duration is initialized by a constant
|
| 19 |
+
initializer for the entity. If constant initialization is not performed,
|
| 20 |
+
a variable with static storage duration ([[basic.stc.static]]) or
|
| 21 |
+
thread storage duration ([[basic.stc.thread]]) is zero-initialized (
|
| 22 |
+
[[dcl.init]]). Together, zero-initialization and constant initialization
|
| 23 |
+
are called *static initialization*; all other initialization is *dynamic
|
| 24 |
+
initialization*. All static initialization strongly happens before (
|
| 25 |
+
[[intro.races]]) any dynamic initialization.
|
| 26 |
+
|
| 27 |
+
[*Note 2*: The dynamic initialization of non-local variables is
|
| 28 |
+
described in [[basic.start.dynamic]]; that of local static variables is
|
| 29 |
+
described in [[stmt.dcl]]. — *end note*]
|
| 30 |
+
|
| 31 |
+
An implementation is permitted to perform the initialization of a
|
| 32 |
+
variable with static or thread storage duration as a static
|
| 33 |
+
initialization even if such initialization is not required to be done
|
| 34 |
+
statically, provided that
|
| 35 |
+
|
| 36 |
+
- the dynamic version of the initialization does not change the value of
|
| 37 |
+
any other object of static or thread storage duration prior to its
|
| 38 |
+
initialization, and
|
| 39 |
+
- the static version of the initialization produces the same value in
|
| 40 |
+
the initialized variable as would be produced by the dynamic
|
| 41 |
+
initialization if all variables not required to be initialized
|
| 42 |
+
statically were initialized dynamically.
|
| 43 |
+
|
| 44 |
+
[*Note 3*:
|
| 45 |
+
|
| 46 |
+
As a consequence, if the initialization of an object `obj1` refers to an
|
| 47 |
+
object `obj2` of namespace scope potentially requiring dynamic
|
| 48 |
+
initialization and defined later in the same translation unit, it is
|
| 49 |
+
unspecified whether the value of `obj2` used will be the value of the
|
| 50 |
+
fully initialized `obj2` (because `obj2` was statically initialized) or
|
| 51 |
+
will be the value of `obj2` merely zero-initialized. For example,
|
| 52 |
+
|
| 53 |
+
``` cpp
|
| 54 |
+
inline double fd() { return 1.0; }
|
| 55 |
+
extern double d1;
|
| 56 |
+
double d2 = d1; // unspecified:
|
| 57 |
+
// may be statically initialized to 0.0 or
|
| 58 |
+
// dynamically initialized to 0.0 if d1 is
|
| 59 |
+
// dynamically initialized, or 1.0 otherwise
|
| 60 |
+
double d1 = fd(); // may be initialized statically or dynamically to 1.0
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
— *end note*]
|
| 64 |
+
|