From Jason Turner

[stmt.return]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmprk3seqq4/{from.md → to.md} +35 -20
tmp/tmprk3seqq4/{from.md → to.md} RENAMED
@@ -1,26 +1,26 @@
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) {
@@ -28,16 +28,31 @@ std::pair<std::string,int> f(const char* p, int 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
 
 
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 [[class.ctor]],
8
+ or a destructor [[class.dtor]]. A `return` statement with an operand of
9
+ type `void` shall be used only in a function whose return type is
10
+ cv `void`. A `return` statement with any other operand shall be used
11
+ only in a function whose return type is not cv `void`; the `return`
12
+ statement initializes the glvalue result or prvalue result object of the
13
+ (explicit or implicit) function call by copy-initialization [[dcl.init]]
14
+ 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.elision]]. — *end note*]
22
 
23
  [*Example 1*:
24
 
25
  ``` cpp
26
  std::pair<std::string,int> f(const char* p, int x) {
 
28
  }
29
  ```
30
 
31
  — *end example*]
32
 
33
+ The destructor for the returned object is potentially invoked (
34
+ [[class.dtor]], [[except.ctor]]).
35
+
36
+ [*Example 2*:
37
+
38
+ ``` cpp
39
+ class A {
40
+ ~A() {}
41
+ };
42
+ A f() { return A(); } // error: destructor of A is private (even though it is never invoked)
43
+ ```
44
+
45
+ — *end example*]
46
+
47
+ Flowing off the end of a constructor, a destructor, or a non-coroutine
48
+ function with a cv `void` return type is equivalent to a `return` with
49
+ no operand. Otherwise, flowing off the end of a function other than
50
+ `main` [[basic.start.main]] or a coroutine [[dcl.fct.def.coroutine]]
51
+ results in undefined behavior.
52
 
53
  The copy-initialization of the result of the call is sequenced before
54
  the destruction of temporaries at the end of the full-expression
55
+ established by the operand of the `return` statement, which, in turn, is
56
+ sequenced before the destruction of local variables [[stmt.jump]] of the
57
+ block enclosing the `return` statement.
58