From Jason Turner

[stmt.dcl]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp_qe7iqzy/{from.md → to.md} +26 -26
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[^3] 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
  ``` 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
- // call for a followed by construction
40
- // again immediately following label ly
41
  }
42
  ```
43
 
44
- The zero-initialization ([[dcl.init]]) of all block-scope variables
45
- with static storage duration ([[basic.stc.static]]) or thread storage
46
- duration ([[basic.stc.thread]]) is performed before any other
47
- initialization takes place. Constant initialization (
48
- [[basic.start.init]]) of a block-scope entity with static storage
49
- duration, if applicable, is performed before its block is first entered.
50
- An implementation is permitted to perform early initialization of other
51
- block-scope variables with static or thread storage duration under the
52
- same conditions that an implementation is permitted to statically
53
- initialize a variable with static or thread storage duration in
54
- namespace scope ([[basic.start.init]]). Otherwise such a variable is
55
- initialized the first time control passes through its declaration; such
56
- a variable is considered initialized upon the completion of its
57
- initialization. If the initialization exits by throwing an exception,
58
- the initialization is not complete, so it will be tried again the next
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
- [[basic.start.term]] describes the order in which block-scope objects
75
- with static and thread storage duration are destroyed.
 
 
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