tmp/tmp_qe7iqzy/{from.md → to.md}
RENAMED
|
@@ -16,61 +16,61 @@ Variables with automatic storage duration ([[basic.stc.auto]]) are
|
|
| 16 |
initialized each time their *declaration-statement* is executed.
|
| 17 |
Variables with automatic storage duration declared in the block are
|
| 18 |
destroyed on exit from the block ([[stmt.jump]]).
|
| 19 |
|
| 20 |
It is possible to transfer into a block, but not in a way that bypasses
|
| 21 |
-
declarations with initialization. A program that jumps[^
|
| 22 |
where a variable with automatic storage duration is not in scope to a
|
| 23 |
point where it is in scope is ill-formed unless the variable has scalar
|
| 24 |
type, class type with a trivial default constructor and a trivial
|
| 25 |
destructor, a cv-qualified version of one of these types, or an array of
|
| 26 |
one of the preceding types and is declared without an *initializer* (
|
| 27 |
[[dcl.init]]).
|
| 28 |
|
|
|
|
|
|
|
| 29 |
``` cpp
|
| 30 |
void f() {
|
| 31 |
// ...
|
| 32 |
goto lx; // ill-formed: jump into scope of a
|
| 33 |
// ...
|
| 34 |
ly:
|
| 35 |
X a = 1;
|
| 36 |
// ...
|
| 37 |
lx:
|
| 38 |
-
goto ly; // OK, jump implies destructor
|
| 39 |
-
//
|
| 40 |
-
// again immediately following label ly
|
| 41 |
}
|
| 42 |
```
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
[[basic.
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
time control enters the declaration. If control enters the declaration
|
| 60 |
-
concurrently while the variable is being initialized, the concurrent
|
| 61 |
-
execution shall wait for completion of the initialization.[^4] If
|
| 62 |
-
control re-enters the declaration recursively while the variable is
|
| 63 |
-
being initialized, the behavior is undefined.
|
| 64 |
|
| 65 |
``` cpp
|
| 66 |
int foo(int i) {
|
| 67 |
static int s = foo(2*i); // recursive call - undefined
|
| 68 |
return i+1;
|
| 69 |
}
|
| 70 |
```
|
| 71 |
|
|
|
|
|
|
|
| 72 |
The destructor for a block-scope object with static or thread storage
|
| 73 |
duration will be executed if and only if it was constructed.
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
| 76 |
|
|
|
|
| 16 |
initialized each time their *declaration-statement* is executed.
|
| 17 |
Variables with automatic storage duration declared in the block are
|
| 18 |
destroyed on exit from the block ([[stmt.jump]]).
|
| 19 |
|
| 20 |
It is possible to transfer into a block, but not in a way that bypasses
|
| 21 |
+
declarations with initialization. A program that jumps[^2] from a point
|
| 22 |
where a variable with automatic storage duration is not in scope to a
|
| 23 |
point where it is in scope is ill-formed unless the variable has scalar
|
| 24 |
type, class type with a trivial default constructor and a trivial
|
| 25 |
destructor, a cv-qualified version of one of these types, or an array of
|
| 26 |
one of the preceding types and is declared without an *initializer* (
|
| 27 |
[[dcl.init]]).
|
| 28 |
|
| 29 |
+
[*Example 1*:
|
| 30 |
+
|
| 31 |
``` cpp
|
| 32 |
void f() {
|
| 33 |
// ...
|
| 34 |
goto lx; // ill-formed: jump into scope of a
|
| 35 |
// ...
|
| 36 |
ly:
|
| 37 |
X a = 1;
|
| 38 |
// ...
|
| 39 |
lx:
|
| 40 |
+
goto ly; // OK, jump implies destructor call for a followed by
|
| 41 |
+
// construction again immediately following label ly
|
|
|
|
| 42 |
}
|
| 43 |
```
|
| 44 |
|
| 45 |
+
— *end example*]
|
| 46 |
+
|
| 47 |
+
Dynamic initialization of a block-scope variable with static storage
|
| 48 |
+
duration ([[basic.stc.static]]) or thread storage duration (
|
| 49 |
+
[[basic.stc.thread]]) is performed the first time control passes through
|
| 50 |
+
its declaration; such a variable is considered initialized upon the
|
| 51 |
+
completion of its initialization. If the initialization exits by
|
| 52 |
+
throwing an exception, the initialization is not complete, so it will be
|
| 53 |
+
tried again the next time control enters the declaration. If control
|
| 54 |
+
enters the declaration concurrently while the variable is being
|
| 55 |
+
initialized, the concurrent execution shall wait for completion of the
|
| 56 |
+
initialization.[^3] If control re-enters the declaration recursively
|
| 57 |
+
while the variable is being initialized, the behavior is undefined.
|
| 58 |
+
|
| 59 |
+
[*Example 2*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
int foo(int i) {
|
| 63 |
static int s = foo(2*i); // recursive call - undefined
|
| 64 |
return i+1;
|
| 65 |
}
|
| 66 |
```
|
| 67 |
|
| 68 |
+
— *end example*]
|
| 69 |
+
|
| 70 |
The destructor for a block-scope object with static or thread storage
|
| 71 |
duration will be executed if and only if it was constructed.
|
| 72 |
+
|
| 73 |
+
[*Note 1*: [[basic.start.term]] describes the order in which
|
| 74 |
+
block-scope objects with static and thread storage duration are
|
| 75 |
+
destroyed. — *end note*]
|
| 76 |
|