From Jason Turner

[stmt.jump]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp3fdv0vgg/{from.md → to.md} +56 -51
tmp/tmp3fdv0vgg/{from.md → to.md} RENAMED
@@ -13,68 +13,40 @@ jump-statement:
13
  goto identifier ';'
14
  ```
15
 
16
  [*Note 1*: On exit from a scope (however accomplished), objects with
17
  automatic storage duration [[basic.stc.auto]] that have been constructed
18
- in that scope are destroyed in the reverse order of their construction.
19
- For temporaries, see  [[class.temporary]]. However, the program can be
20
- terminated (by calling `std::exit()` or `std::abort()`
21
  [[support.start.term]], for example) without destroying objects with
22
  automatic storage duration. — *end note*]
23
 
24
  [*Note 2*: A suspension of a coroutine [[expr.await]] is not considered
25
  to be an exit from a scope. — *end note*]
26
 
27
  ### The `break` statement <a id="stmt.break">[[stmt.break]]</a>
28
 
29
  A `break` statement shall be enclosed by [[stmt.pre]] an
30
- *iteration-statement* [[stmt.iter]] or a `switch` statement
31
- [[stmt.switch]]. The `break` statement causes termination of the
32
- smallest such enclosing statement; control passes to the statement
33
- following the terminated statement, if any.
 
34
 
35
  ### The `continue` statement <a id="stmt.cont">[[stmt.cont]]</a>
36
 
37
  A `continue` statement shall be enclosed by [[stmt.pre]] an
38
- *iteration-statement* [[stmt.iter]]. The `continue` statement causes
39
- control to pass to the loop-continuation portion of the smallest such
40
- enclosing statement, that is, to the end of the loop. More precisely, in
41
- each of the statements
42
-
43
- ``` cpp
44
- while (foo) {
45
- {
46
- // ...
47
- }
48
- contin: ;
49
- }
50
- ```
51
-
52
- ``` cpp
53
- do {
54
- {
55
- // ...
56
- }
57
- contin: ;
58
- } while (foo);
59
- ```
60
-
61
- ``` cpp
62
- for (;;) {
63
- {
64
- // ...
65
- }
66
- contin: ;
67
- }
68
- ```
69
-
70
- a `continue` not contained in an enclosed iteration statement is
71
- equivalent to `goto` *`contin`*.
72
 
73
  ### The `return` statement <a id="stmt.return">[[stmt.return]]</a>
74
 
75
- A function returns to its caller by the `return` statement.
76
 
77
  The *expr-or-braced-init-list* of a `return` statement is called its
78
  operand. A `return` statement with no operand shall be used only in a
79
  function whose return type is cv `void`, a constructor [[class.ctor]],
80
  or a destructor [[class.dtor]]. A `return` statement with an operand of
@@ -119,31 +91,63 @@ The copy-initialization of the result of the call is sequenced before
119
  the destruction of temporaries at the end of the full-expression
120
  established by the operand of the `return` statement, which, in turn, is
121
  sequenced before the destruction of local variables [[stmt.jump]] of the
122
  block enclosing the `return` statement.
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  ### The `co_return` statement <a id="stmt.return.coroutine">[[stmt.return.coroutine]]</a>
125
 
126
  ``` bnf
127
  coroutine-return-statement:
128
- 'co_return' expr-or-braced-init-listₒₚₜ ';'
129
  ```
130
 
131
- A coroutine returns to its caller or resumer [[dcl.fct.def.coroutine]]
132
- by the `co_return` statement or when suspended [[expr.await]]. A
133
- coroutine shall not enclose a `return` statement [[stmt.return]].
134
 
135
  [*Note 1*: For this determination, it is irrelevant whether the
136
  `return` statement is enclosed by a discarded statement
137
  [[stmt.if]]. — *end note*]
138
 
139
  The *expr-or-braced-init-list* of a `co_return` statement is called its
140
  operand. Let *p* be an lvalue naming the coroutine promise object
141
  [[dcl.fct.def.coroutine]]. A `co_return` statement is equivalent to:
142
 
143
  ``` bnf
144
- '{' S';' 'goto' final-suspend';' '}'
145
  ```
146
 
147
  where *`final-suspend`* is the exposition-only label defined in
148
  [[dcl.fct.def.coroutine]] and *S* is defined as follows:
149
 
@@ -152,14 +156,15 @@ where *`final-suspend`* is the exposition-only label defined in
152
  expression *S* shall be a prvalue of type `void`.
153
  - Otherwise, *S* is the *compound-statement* `{` *expression*ₒₚₜ `;`
154
  *p*`.return_void()``; }`. The expression *p*`.return_void()` shall be
155
  a prvalue of type `void`.
156
 
157
- If *p*`.return_void()` is a valid expression, flowing off the end of a
158
- coroutine’s *function-body* is equivalent to a `co_return` with no
159
- operand; otherwise flowing off the end of a coroutine’s *function-body*
160
- results in undefined behavior.
 
161
 
162
  ### The `goto` statement <a id="stmt.goto">[[stmt.goto]]</a>
163
 
164
  The `goto` statement unconditionally transfers control to the statement
165
  labeled by the identifier. The identifier shall be a label
 
13
  goto identifier ';'
14
  ```
15
 
16
  [*Note 1*: On exit from a scope (however accomplished), objects with
17
  automatic storage duration [[basic.stc.auto]] that have been constructed
18
+ in that scope are destroyed in the reverse order of their construction
19
+ [[stmt.dcl]]. For temporaries, see  [[class.temporary]]. However, the
20
+ program can be terminated (by calling `std::exit()` or `std::abort()`
21
  [[support.start.term]], for example) without destroying objects with
22
  automatic storage duration. — *end note*]
23
 
24
  [*Note 2*: A suspension of a coroutine [[expr.await]] is not considered
25
  to be an exit from a scope. — *end note*]
26
 
27
  ### The `break` statement <a id="stmt.break">[[stmt.break]]</a>
28
 
29
  A `break` statement shall be enclosed by [[stmt.pre]] an
30
+ *iteration-statement* [[stmt.iter]], an *expansion-statement*
31
+ [[stmt.expand]], or a `switch` statement [[stmt.switch]]. The `break`
32
+ statement causes termination of the innermost such enclosing statement;
33
+ control passes to the statement following the terminated statement, if
34
+ any.
35
 
36
  ### The `continue` statement <a id="stmt.cont">[[stmt.cont]]</a>
37
 
38
  A `continue` statement shall be enclosed by [[stmt.pre]] an
39
+ *iteration-statement* or an *expansion-statement*. If the innermost
40
+ enclosing such statement X is an *iteration-statement* [[stmt.iter]],
41
+ the `continue` statement causes control to pass to the end of the
42
+ *statement* or *compound-statement* of X. Otherwise, control passes to
43
+ the end of the *compound-statement* of the current Sᵢ [[stmt.expand]].
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  ### The `return` statement <a id="stmt.return">[[stmt.return]]</a>
46
 
47
+ A function returns control to its caller by the `return` statement.
48
 
49
  The *expr-or-braced-init-list* of a `return` statement is called its
50
  operand. A `return` statement with no operand shall be used only in a
51
  function whose return type is cv `void`, a constructor [[class.ctor]],
52
  or a destructor [[class.dtor]]. A `return` statement with an operand of
 
91
  the destruction of temporaries at the end of the full-expression
92
  established by the operand of the `return` statement, which, in turn, is
93
  sequenced before the destruction of local variables [[stmt.jump]] of the
94
  block enclosing the `return` statement.
95
 
96
+ [*Note 3*: These operations are sequenced before the destruction of
97
+ local variables in each remaining enclosing block of the function
98
+ [[stmt.dcl]], which, in turn, is sequenced before the evaluation of
99
+ postcondition assertions of the function [[dcl.contract.func]], which,
100
+ in turn, is sequenced before the destruction of function parameters
101
+ [[expr.call]]. — *end note*]
102
+
103
+ In a function whose return type is a reference, other than an invented
104
+ function for `std::is_convertible` [[meta.rel]], a `return` statement
105
+ that binds the returned reference to a temporary expression
106
+ [[class.temporary]] is ill-formed.
107
+
108
+ [*Example 2*:
109
+
110
+ ``` cpp
111
+ auto&& f1() {
112
+ return 42; // ill-formed
113
+ }
114
+ const double& f2() {
115
+ static int x = 42;
116
+ return x; // ill-formed
117
+ }
118
+ auto&& id(auto&& r) {
119
+ return static_cast<decltype(r)&&>(r);
120
+ }
121
+ auto&& f3() {
122
+ return id(42); // OK, but probably a bug
123
+ }
124
+ ```
125
+
126
+ — *end example*]
127
+
128
  ### The `co_return` statement <a id="stmt.return.coroutine">[[stmt.return.coroutine]]</a>
129
 
130
  ``` bnf
131
  coroutine-return-statement:
132
+ co_return expr-or-braced-init-listₒₚₜ ';'
133
  ```
134
 
135
+ A `co_return` statement transfers control to the caller or resumer of a
136
+ coroutine [[dcl.fct.def.coroutine]]. A coroutine shall not enclose a
137
+ `return` statement [[stmt.return]].
138
 
139
  [*Note 1*: For this determination, it is irrelevant whether the
140
  `return` statement is enclosed by a discarded statement
141
  [[stmt.if]]. — *end note*]
142
 
143
  The *expr-or-braced-init-list* of a `co_return` statement is called its
144
  operand. Let *p* be an lvalue naming the coroutine promise object
145
  [[dcl.fct.def.coroutine]]. A `co_return` statement is equivalent to:
146
 
147
  ``` bnf
148
+ '{' S';' goto final-suspend';' '}'
149
  ```
150
 
151
  where *`final-suspend`* is the exposition-only label defined in
152
  [[dcl.fct.def.coroutine]] and *S* is defined as follows:
153
 
 
156
  expression *S* shall be a prvalue of type `void`.
157
  - Otherwise, *S* is the *compound-statement* `{` *expression*ₒₚₜ `;`
158
  *p*`.return_void()``; }`. The expression *p*`.return_void()` shall be
159
  a prvalue of type `void`.
160
 
161
+ If a search for the name `return_void` in the scope of the promise type
162
+ finds any declarations, flowing off the end of a coroutine’s
163
+ *function-body* is equivalent to a `co_return` with no operand;
164
+ otherwise flowing off the end of a coroutine’s *function-body* results
165
+ in undefined behavior.
166
 
167
  ### The `goto` statement <a id="stmt.goto">[[stmt.goto]]</a>
168
 
169
  The `goto` statement unconditionally transfers control to the statement
170
  labeled by the identifier. The identifier shall be a label