From Jason Turner

[stmt.jump]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp3i4lvy39/{from.md → to.md} +87 -31
tmp/tmp3i4lvy39/{from.md → to.md} RENAMED
@@ -2,33 +2,37 @@
2
 
3
  Jump statements unconditionally transfer control.
4
 
5
  ``` bnf
6
  jump-statement:
7
- 'break ;'
8
- 'continue ;'
9
- 'return' expr-or-braced-init-listₒₚₜ ';'
10
- 'goto' identifier ';'
 
11
  ```
12
 
13
  On exit from a scope (however accomplished), objects with automatic
14
- storage duration ([[basic.stc.auto]]) that have been constructed in
15
- that scope are destroyed in the reverse order of their construction.
16
 
17
  [*Note 1*: For temporaries, see  [[class.temporary]]. — *end note*]
18
 
19
  Transfer out of a loop, out of a block, or back past an initialized
20
  variable with automatic storage duration involves the destruction of
21
  objects with automatic storage duration that are in scope at the point
22
  transferred from but not at the point transferred to. (See  [[stmt.dcl]]
23
  for transfers into blocks).
24
 
25
  [*Note 2*: However, the program can be terminated (by calling
26
- `std::exit()` or `std::abort()` ([[support.start.term]]), for example)
27
- without destroying class objects with automatic storage
28
  duration. — *end note*]
29
 
 
 
 
30
  ### The `break` statement <a id="stmt.break">[[stmt.break]]</a>
31
 
32
  The `break` statement shall occur only in an *iteration-statement* or a
33
  `switch` statement and causes termination of the smallest enclosing
34
  *iteration-statement* or `switch` statement; control passes to the
@@ -67,33 +71,33 @@ for (;;) {
67
  contin: ;
68
  }
69
  ```
70
 
71
  a `continue` not contained in an enclosed iteration statement is
72
- equivalent to `goto` `contin`.
73
 
74
  ### The `return` statement <a id="stmt.return">[[stmt.return]]</a>
75
 
76
  A function returns to its caller by the `return` statement.
77
 
78
- The *expr-or-braced-init-list* of a return statement is called its
79
- operand. A return statement with no operand shall be used only in a
80
- function whose return type is cv `void`, a constructor (
81
- [[class.ctor]]), or a destructor ([[class.dtor]]). A return statement
82
- with an operand of type `void` shall be used only in a function whose
83
- return type is cv `void`. A return statement with any other operand
84
- shall be used only in a function whose return type is not cv `void`; the
85
- return statement initializes the glvalue result or prvalue result object
86
- of the (explicit or implicit) function call by copy-initialization (
87
- [[dcl.init]]) from the operand.
88
 
89
- [*Note 1*: A return statement can involve an invocation of a
90
  constructor to perform a copy or move of the operand if it is not a
91
  prvalue or if its type differs from the return type of the function. A
92
- copy operation associated with a return statement may be elided or
93
  converted to a move operation if an automatic storage duration variable
94
- is returned ([[class.copy]]). — *end note*]
95
 
96
  [*Example 1*:
97
 
98
  ``` cpp
99
  std::pair<std::string,int> f(const char* p, int x) {
@@ -101,22 +105,74 @@ std::pair<std::string,int> f(const char* p, int x) {
101
  }
102
  ```
103
 
104
  — *end example*]
105
 
106
- Flowing off the end of a constructor, a destructor, or a function with a
107
- cv `void` return type is equivalent to a `return` with no operand.
108
- Otherwise, flowing off the end of a function other than `main` (
109
- [[basic.start.main]]) results in undefined behavior.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  The copy-initialization of the result of the call is sequenced before
112
  the destruction of temporaries at the end of the full-expression
113
- established by the operand of the return statement, which, in turn, is
114
- sequenced before the destruction of local variables ([[stmt.jump]]) of
115
- the block enclosing the return statement.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  ### The `goto` statement <a id="stmt.goto">[[stmt.goto]]</a>
118
 
119
  The `goto` statement unconditionally transfers control to the statement
120
- labeled by the identifier. The identifier shall be a label (
121
- [[stmt.label]]) located in the current function.
122
 
 
2
 
3
  Jump statements unconditionally transfer control.
4
 
5
  ``` bnf
6
  jump-statement:
7
+ break ';'
8
+ continue ';'
9
+ return expr-or-braced-init-listₒₚₜ ';'
10
+ coroutine-return-statement
11
+ goto identifier ';'
12
  ```
13
 
14
  On exit from a scope (however accomplished), objects with automatic
15
+ storage duration [[basic.stc.auto]] that have been constructed in that
16
+ scope are destroyed in the reverse order of their construction.
17
 
18
  [*Note 1*: For temporaries, see  [[class.temporary]]. — *end note*]
19
 
20
  Transfer out of a loop, out of a block, or back past an initialized
21
  variable with automatic storage duration involves the destruction of
22
  objects with automatic storage duration that are in scope at the point
23
  transferred from but not at the point transferred to. (See  [[stmt.dcl]]
24
  for transfers into blocks).
25
 
26
  [*Note 2*: However, the program can be terminated (by calling
27
+ `std::exit()` or `std::abort()` [[support.start.term]], for example)
28
+ without destroying objects with automatic storage
29
  duration. — *end note*]
30
 
31
+ [*Note 3*: A suspension of a coroutine [[expr.await]] is not considered
32
+ to be an exit from a scope. — *end note*]
33
+
34
  ### The `break` statement <a id="stmt.break">[[stmt.break]]</a>
35
 
36
  The `break` statement shall occur only in an *iteration-statement* or a
37
  `switch` statement and causes termination of the smallest enclosing
38
  *iteration-statement* or `switch` statement; control passes to the
 
71
  contin: ;
72
  }
73
  ```
74
 
75
  a `continue` not contained in an enclosed iteration statement is
76
+ equivalent to `goto` *`contin`*.
77
 
78
  ### The `return` statement <a id="stmt.return">[[stmt.return]]</a>
79
 
80
  A function returns to its caller by the `return` statement.
81
 
82
+ The *expr-or-braced-init-list* of a `return` statement is called its
83
+ operand. A `return` statement with no operand shall be used only in a
84
+ function whose return type is cv `void`, a constructor [[class.ctor]],
85
+ or a destructor [[class.dtor]]. A `return` statement with an operand of
86
+ type `void` shall be used only in a function whose return type is
87
+ cv `void`. A `return` statement with any other operand shall be used
88
+ only in a function whose return type is not cv `void`; the `return`
89
+ statement initializes the glvalue result or prvalue result object of the
90
+ (explicit or implicit) function call by copy-initialization [[dcl.init]]
91
+ from the operand.
92
 
93
+ [*Note 1*: A `return` statement can involve an invocation of a
94
  constructor to perform a copy or move of the operand if it is not a
95
  prvalue or if its type differs from the return type of the function. A
96
+ copy operation associated with a `return` statement may be elided or
97
  converted to a move operation if an automatic storage duration variable
98
+ is returned [[class.copy.elision]]. — *end note*]
99
 
100
  [*Example 1*:
101
 
102
  ``` cpp
103
  std::pair<std::string,int> f(const char* p, int x) {
 
105
  }
106
  ```
107
 
108
  — *end example*]
109
 
110
+ The destructor for the returned object is potentially invoked (
111
+ [[class.dtor]], [[except.ctor]]).
112
+
113
+ [*Example 2*:
114
+
115
+ ``` cpp
116
+ class A {
117
+ ~A() {}
118
+ };
119
+ A f() { return A(); } // error: destructor of A is private (even though it is never invoked)
120
+ ```
121
+
122
+ — *end example*]
123
+
124
+ Flowing off the end of a constructor, a destructor, or a non-coroutine
125
+ function with a cv `void` return type is equivalent to a `return` with
126
+ no operand. Otherwise, flowing off the end of a function other than
127
+ `main` [[basic.start.main]] or a coroutine [[dcl.fct.def.coroutine]]
128
+ results in undefined behavior.
129
 
130
  The copy-initialization of the result of the call is sequenced before
131
  the destruction of temporaries at the end of the full-expression
132
+ established by the operand of the `return` statement, which, in turn, is
133
+ sequenced before the destruction of local variables [[stmt.jump]] of the
134
+ block enclosing the `return` statement.
135
+
136
+ ### The `co_return` statement <a id="stmt.return.coroutine">[[stmt.return.coroutine]]</a>
137
+
138
+ ``` bnf
139
+ coroutine-return-statement:
140
+ 'co_return' expr-or-braced-init-listₒₚₜ ';'
141
+ ```
142
+
143
+ A coroutine returns to its caller or resumer [[dcl.fct.def.coroutine]]
144
+ by the `co_return` statement or when suspended [[expr.await]]. A
145
+ coroutine shall not enclose a `return` statement [[stmt.return]].
146
+
147
+ [*Note 1*: For this determination, it is irrelevant whether the
148
+ `return` statement is enclosed by a discarded statement
149
+ [[stmt.if]]. — *end note*]
150
+
151
+ The *expr-or-braced-init-list* of a `co_return` statement is called its
152
+ operand. Let *p* be an lvalue naming the coroutine promise object
153
+ [[dcl.fct.def.coroutine]]. A `co_return` statement is equivalent to:
154
+
155
+ ``` bnf
156
+ '{' S';' 'goto' final-suspend';' '}'
157
+ ```
158
+
159
+ where *`final-suspend`* is the exposition-only label defined in
160
+ [[dcl.fct.def.coroutine]] and *S* is defined as follows:
161
+
162
+ - If the operand is a *braced-init-list* or an expression of non-`void`
163
+ type, *S* is *p*`.return_value(`*expr-or-braced-init-list*`)`. The
164
+ expression *S* shall be a prvalue of type `void`.
165
+ - Otherwise, *S* is the *compound-statement* `{` *expression*ₒₚₜ `;`
166
+ *p*`.return_void()``; }`. The expression *p*`.return_void()` shall be
167
+ a prvalue of type `void`.
168
+
169
+ If *p*`.return_void()` is a valid expression, flowing off the end of a
170
+ coroutine is equivalent to a `co_return` with no operand; otherwise
171
+ flowing off the end of a coroutine results in undefined behavior.
172
 
173
  ### The `goto` statement <a id="stmt.goto">[[stmt.goto]]</a>
174
 
175
  The `goto` statement unconditionally transfers control to the statement
176
+ labeled by the identifier. The identifier shall be a label
177
+ [[stmt.label]] located in the current function.
178