From Jason Turner

[stmt.dcl]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpw2pd2nau/{from.md → to.md} +40 -33
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 identifiers into a
4
- block; it has the form
5
 
6
  ``` bnf
7
  declaration-statement:
8
  block-declaration
9
  ```
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() {
@@ -42,21 +44,27 @@ lx:
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) {
@@ -65,12 +73,11 @@ int foo(int i) {
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
 
 
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