tmp/tmpw2pd2nau/{from.md → to.md}
RENAMED
|
@@ -1,32 +1,34 @@
|
|
| 1 |
## Declaration statement <a id="stmt.dcl">[[stmt.dcl]]</a>
|
| 2 |
|
| 3 |
-
A declaration statement introduces one or more new
|
| 4 |
-
|
| 5 |
|
| 6 |
``` bnf
|
| 7 |
declaration-statement:
|
| 8 |
block-declaration
|
| 9 |
```
|
| 10 |
|
| 11 |
-
If an identifier introduced by a declaration was previously
|
| 12 |
-
an outer block, the outer declaration is hidden for the
|
| 13 |
-
block, after which it resumes
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 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() {
|
|
@@ -42,21 +44,27 @@ lx:
|
|
| 42 |
}
|
| 43 |
```
|
| 44 |
|
| 45 |
— *end example*]
|
| 46 |
|
| 47 |
-
Dynamic initialization of a block
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
[*Example 2*:
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
int foo(int i) {
|
|
@@ -65,12 +73,11 @@ int foo(int i) {
|
|
| 65 |
}
|
| 66 |
```
|
| 67 |
|
| 68 |
— *end example*]
|
| 69 |
|
| 70 |
-
|
| 71 |
-
destroyed if and only if it was constructed.
|
| 72 |
|
| 73 |
-
[*Note
|
| 74 |
-
|
| 75 |
-
destroyed. — *end note*]
|
| 76 |
|
|
|
|
| 1 |
## Declaration statement <a id="stmt.dcl">[[stmt.dcl]]</a>
|
| 2 |
|
| 3 |
+
A declaration statement introduces one or more new names into a block;
|
| 4 |
+
it has the form
|
| 5 |
|
| 6 |
``` bnf
|
| 7 |
declaration-statement:
|
| 8 |
block-declaration
|
| 9 |
```
|
| 10 |
|
| 11 |
+
[*Note 1*: If an identifier introduced by a declaration was previously
|
| 12 |
+
declared in an outer block, the outer declaration is hidden for the
|
| 13 |
+
remainder of the block [[basic.lookup.unqual]], after which it resumes
|
| 14 |
+
its force. — *end note*]
|
| 15 |
|
| 16 |
+
A variable with automatic storage duration [[basic.stc.auto]] is
|
| 17 |
+
*active* everywhere in the scope to which it belongs after its
|
| 18 |
+
*init-declarator*. Upon each transfer of control (including sequential
|
| 19 |
+
execution of statements) within a function from point P to point Q, all
|
| 20 |
+
variables with automatic storage duration that are active at P and not
|
| 21 |
+
at Q are destroyed in the reverse order of their construction. Then, all
|
| 22 |
+
variables with automatic storage duration that are active at Q but not
|
| 23 |
+
at P are initialized in declaration order; unless all such variables
|
| 24 |
+
have vacuous initialization [[basic.life]], the transfer of control
|
| 25 |
+
shall not be a jump.[^2]
|
| 26 |
|
| 27 |
+
When a *declaration-statement* is executed, P and Q are the points
|
| 28 |
+
immediately before and after it; when a function returns, Q is after its
|
| 29 |
+
body.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
[*Example 1*:
|
| 32 |
|
| 33 |
``` cpp
|
| 34 |
void f() {
|
|
|
|
| 44 |
}
|
| 45 |
```
|
| 46 |
|
| 47 |
— *end example*]
|
| 48 |
|
| 49 |
+
Dynamic initialization of a block variable with static storage duration
|
| 50 |
+
[[basic.stc.static]] or thread storage duration [[basic.stc.thread]] is
|
| 51 |
+
performed the first time control passes through its declaration; such a
|
| 52 |
+
variable is considered initialized upon the completion of its
|
| 53 |
+
initialization. If the initialization exits by throwing an exception,
|
| 54 |
+
the initialization is not complete, so it will be tried again the next
|
| 55 |
+
time control enters the declaration. If control enters the declaration
|
| 56 |
+
concurrently while the variable is being initialized, the concurrent
|
| 57 |
+
execution shall wait for completion of the initialization.
|
| 58 |
+
|
| 59 |
+
[*Note 2*: A conforming implementation cannot introduce any deadlock
|
| 60 |
+
around execution of the initializer. Deadlocks might still be caused by
|
| 61 |
+
the program logic; the implementation need only avoid deadlocks due to
|
| 62 |
+
its own synchronization operations. — *end note*]
|
| 63 |
+
|
| 64 |
+
If control re-enters the declaration recursively while the variable is
|
| 65 |
+
being initialized, the behavior is undefined.
|
| 66 |
|
| 67 |
[*Example 2*:
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
int foo(int i) {
|
|
|
|
| 73 |
}
|
| 74 |
```
|
| 75 |
|
| 76 |
— *end example*]
|
| 77 |
|
| 78 |
+
An object associated with a block variable with static or thread storage
|
| 79 |
+
duration will be destroyed if and only if it was constructed.
|
| 80 |
|
| 81 |
+
[*Note 3*: [[basic.start.term]] describes the order in which such
|
| 82 |
+
objects are destroyed. — *end note*]
|
|
|
|
| 83 |
|