tmp/tmpg8hc1zem/{from.md → to.md}
RENAMED
|
@@ -10,30 +10,30 @@ declaration-statement:
|
|
| 10 |
|
| 11 |
If an identifier introduced by a declaration was previously declared in
|
| 12 |
an outer block, the outer declaration is hidden for the remainder of the
|
| 13 |
block, after which it resumes its force.
|
| 14 |
|
| 15 |
-
Variables with automatic storage duration
|
| 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
|
| 19 |
|
| 20 |
It is possible to transfer into a block, but not in a way that bypasses
|
| 21 |
-
declarations with initialization
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
[*Example 1*:
|
| 30 |
|
| 31 |
``` cpp
|
| 32 |
void f() {
|
| 33 |
// ...
|
| 34 |
-
goto lx; //
|
| 35 |
// ...
|
| 36 |
ly:
|
| 37 |
X a = 1;
|
| 38 |
// ...
|
| 39 |
lx:
|
|
@@ -43,12 +43,12 @@ lx:
|
|
| 43 |
```
|
| 44 |
|
| 45 |
— *end example*]
|
| 46 |
|
| 47 |
Dynamic initialization of a block-scope variable with static storage
|
| 48 |
-
duration
|
| 49 |
-
[[basic.stc.thread]]
|
| 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
|
|
@@ -58,19 +58,19 @@ 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); //
|
| 64 |
return i+1;
|
| 65 |
}
|
| 66 |
```
|
| 67 |
|
| 68 |
— *end example*]
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 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 |
|
|
|
|
| 10 |
|
| 11 |
If an identifier introduced by a declaration was previously declared in
|
| 12 |
an outer block, the outer declaration is hidden for the remainder of the
|
| 13 |
block, after which it resumes its force.
|
| 14 |
|
| 15 |
+
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 (including ones in *condition*s and
|
| 22 |
+
*init-statement*s). A program that jumps[^2] from a point where a
|
| 23 |
+
variable with automatic storage duration is not in scope to a point
|
| 24 |
+
where it is in scope is ill-formed unless the variable has vacuous
|
| 25 |
+
initialization [[basic.life]]. In such a case, the variables with
|
| 26 |
+
vacuous initialization are constructed in the order of their
|
| 27 |
+
declaration.
|
| 28 |
|
| 29 |
[*Example 1*:
|
| 30 |
|
| 31 |
``` cpp
|
| 32 |
void f() {
|
| 33 |
// ...
|
| 34 |
+
goto lx; // error: jump into scope of a
|
| 35 |
// ...
|
| 36 |
ly:
|
| 37 |
X a = 1;
|
| 38 |
// ...
|
| 39 |
lx:
|
|
|
|
| 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
|
|
|
|
| 58 |
|
| 59 |
[*Example 2*:
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
int foo(int i) {
|
| 63 |
+
static int s = foo(2*i); // undefined behavior: recursive call
|
| 64 |
return i+1;
|
| 65 |
}
|
| 66 |
```
|
| 67 |
|
| 68 |
— *end example*]
|
| 69 |
|
| 70 |
+
A block-scope object with static or thread storage duration will be
|
| 71 |
+
destroyed 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 |
|