From Jason Turner

[stmt.return]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpr1psvmab/{from.md → to.md} +16 -23
tmp/tmpr1psvmab/{from.md → to.md} RENAMED
@@ -4,39 +4,32 @@ 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) {
27
- return {p,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)
@@ -44,12 +37,12 @@ A f() { return A(); } // error: destructor of A is private (even though it is
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
 
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 that has a cv `void` return
10
+ type. A `return` statement with any other operand shall be used only in
11
+ a function that has a return type other than cv `void`; the `return`
12
+ statement initializes the returned reference or prvalue result object of
13
+ the (explicit or implicit) function call by copy-initialization
14
+ [[dcl.init]] from the operand.
15
 
16
+ [*Note 1*: A constructor or destructor does not have a return
17
+ type. — *end note*]
18
+
19
+ [*Note 2*: A `return` statement can involve an invocation of a
20
  constructor to perform a copy or move of the operand if it is not a
21
  prvalue or if its type differs from the return type of the function. A
22
+ copy operation associated with a `return` statement can be elided or
23
  converted to a move operation if an automatic storage duration variable
24
  is returned [[class.copy.elision]]. — *end note*]
25
 
26
+ The destructor for the result object is potentially invoked
27
+ [[class.dtor]], [[except.ctor]].
28
+
29
  [*Example 1*:
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  ``` cpp
32
  class A {
33
  ~A() {}
34
  };
35
  A f() { return A(); } // error: destructor of A is private (even though it is never invoked)
 
37
 
38
  — *end example*]
39
 
40
  Flowing off the end of a constructor, a destructor, or a non-coroutine
41
  function with a cv `void` return type is equivalent to a `return` with
42
+ no operand. Otherwise, flowing off the end of a function that is neither
43
+ `main` [[basic.start.main]] nor a coroutine [[dcl.fct.def.coroutine]]
44
  results in undefined behavior.
45
 
46
  The copy-initialization of the result of the call is sequenced before
47
  the destruction of temporaries at the end of the full-expression
48
  established by the operand of the `return` statement, which, in turn, is