From Jason Turner

[stmt.return]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpj7iwm1ic/{from.md → to.md} +29 -19
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
- A return statement with neither an *expression* nor a *braced-init-list*
6
- can be used only in functions that do not return a value, that is, a
7
- function with the return type cv `void`, a constructor (
8
  [[class.ctor]]), or a destructor ([[class.dtor]]). A return statement
9
- with an expression of non-void type can be used only in functions
10
- returning a value; the value of the expression is returned to the caller
11
- of the function. The value of the expression is implicitly converted to
12
- the return type of the function in which it appears. A return statement
13
- can involve the construction and copy or move of a temporary object (
14
- [[class.temporary]]). A copy or move operation associated with a return
15
- statement may be elided or considered as an rvalue for the purpose of
16
- overload resolution in selecting a constructor ([[class.copy]]). A
17
- return statement with a *braced-init-list* initializes the object or
18
- reference to be returned from the function by copy-list-initialization (
19
- [[dcl.init.list]]) from the specified initializer list.
 
 
 
 
20
 
21
  ``` cpp
22
  std::pair<std::string,int> f(const char* p, int x) {
23
  return {p,x};
24
  }
25
  ```
26
 
27
- Flowing off the end of a function is equivalent to a `return` with no
28
- value; this results in undefined behavior in a value-returning function.
29
 
30
- A return statement with an expression of type `void` can be used only in
31
- functions with a return type of *cv* `void`; the expression is evaluated
32
- just before the function returns to its caller.
 
 
 
 
 
 
 
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