tmp/tmpj7iwm1ic/{from.md → to.md}
RENAMED
|
@@ -1,33 +1,43 @@
|
|
| 1 |
### The `return` statement <a id="stmt.return">[[stmt.return]]</a>
|
| 2 |
|
| 3 |
A function returns to its caller by the `return` statement.
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
function
|
| 8 |
[[class.ctor]]), or a destructor ([[class.dtor]]). A return statement
|
| 9 |
-
with an
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
[[
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
std::pair<std::string,int> f(const char* p, int x) {
|
| 23 |
return {p,x};
|
| 24 |
}
|
| 25 |
```
|
| 26 |
|
| 27 |
-
|
| 28 |
-
value; this results in undefined behavior in a value-returning function.
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
| 1 |
### The `return` statement <a id="stmt.return">[[stmt.return]]</a>
|
| 2 |
|
| 3 |
A function returns to its caller by the `return` statement.
|
| 4 |
|
| 5 |
+
The *expr-or-braced-init-list* of a return statement is called its
|
| 6 |
+
operand. A return statement with no operand shall be used only in a
|
| 7 |
+
function whose return type is cv `void`, a constructor (
|
| 8 |
[[class.ctor]]), or a destructor ([[class.dtor]]). A return statement
|
| 9 |
+
with an operand of type `void` shall be used only in a function whose
|
| 10 |
+
return type is cv `void`. A return statement with any other operand
|
| 11 |
+
shall be used only in a function whose return type is not cv `void`; the
|
| 12 |
+
return statement initializes the glvalue result or prvalue result object
|
| 13 |
+
of the (explicit or implicit) function call by copy-initialization (
|
| 14 |
+
[[dcl.init]]) from the operand.
|
| 15 |
+
|
| 16 |
+
[*Note 1*: A return statement can involve an invocation of a
|
| 17 |
+
constructor to perform a copy or move of the operand if it is not a
|
| 18 |
+
prvalue or if its type differs from the return type of the function. A
|
| 19 |
+
copy operation associated with a return statement may be elided or
|
| 20 |
+
converted to a move operation if an automatic storage duration variable
|
| 21 |
+
is returned ([[class.copy]]). — *end note*]
|
| 22 |
+
|
| 23 |
+
[*Example 1*:
|
| 24 |
|
| 25 |
``` cpp
|
| 26 |
std::pair<std::string,int> f(const char* p, int x) {
|
| 27 |
return {p,x};
|
| 28 |
}
|
| 29 |
```
|
| 30 |
|
| 31 |
+
— *end example*]
|
|
|
|
| 32 |
|
| 33 |
+
Flowing off the end of a constructor, a destructor, or a function with a
|
| 34 |
+
cv `void` return type is equivalent to a `return` with no operand.
|
| 35 |
+
Otherwise, flowing off the end of a function other than `main` (
|
| 36 |
+
[[basic.start.main]]) results in undefined behavior.
|
| 37 |
+
|
| 38 |
+
The copy-initialization of the result of the call is sequenced before
|
| 39 |
+
the destruction of temporaries at the end of the full-expression
|
| 40 |
+
established by the operand of the return statement, which, in turn, is
|
| 41 |
+
sequenced before the destruction of local variables ([[stmt.jump]]) of
|
| 42 |
+
the block enclosing the return statement.
|
| 43 |
|