From Jason Turner

[class.temporary]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmprm3ucrc5/{from.md → to.md} +25 -27
tmp/tmprm3ucrc5/{from.md → to.md} RENAMED
@@ -2,23 +2,21 @@
2
 
3
  Temporaries of class type are created in various contexts: binding a
4
  reference to a prvalue ([[dcl.init.ref]]), returning a prvalue (
5
  [[stmt.return]]), a conversion that creates a prvalue ([[conv.lval]],
6
  [[expr.static.cast]], [[expr.const.cast]], [[expr.cast]]), throwing an
7
- exception ([[except.throw]]), entering a *handler* (
8
- [[except.handle]]), and in some initializations ([[dcl.init]]). The
9
- lifetime of exception objects is described in  [[except.throw]]. Even
10
- when the creation of the temporary object is unevaluated (Clause 
11
- [[expr]]) or otherwise avoided ([[class.copy]]), all the semantic
12
- restrictions shall be respected as if the temporary object had been
13
- created and later destroyed. even if there is no call to the destructor
14
- or copy/move constructor, all the semantic restrictions, such as
15
- accessibility (Clause  [[class.access]]) and whether the function is
16
- deleted ([[dcl.fct.def.delete]]), shall be satisfied. However, in the
17
- special case of a function call used as the operand of a
18
- *decltype-specifier* ([[expr.call]]), no temporary is introduced, so
19
- the foregoing does not apply to the prvalue of any such function call.
20
 
21
  Consider the following code:
22
 
23
  ``` cpp
24
  class X {
@@ -79,18 +77,18 @@ point than the end of the full-expression. The first context is when a
79
  default constructor is called to initialize an element of an array. If
80
  the constructor has one or more default arguments, the destruction of
81
  every temporary created in a default argument is sequenced before the
82
  construction of the next array element, if any.
83
 
84
- The second context is when a reference is bound to a temporary. The
85
  temporary to which the reference is bound or the temporary that is the
86
  complete object of a subobject to which the reference is bound persists
87
  for the lifetime of the reference except:
88
 
89
  - A temporary bound to a reference member in a constructor’s
90
- ctor-initializer ([[class.base.init]]) persists until the constructor
91
- exits.
92
  - A temporary bound to a reference parameter in a function call (
93
  [[expr.call]]) persists until the completion of the full-expression
94
  containing the call.
95
  - The lifetime of a temporary bound to the returned value in a function
96
  return statement ([[stmt.return]]) is not extended; the temporary is
@@ -139,17 +137,17 @@ the expression `S(16) + S(23)` creates three temporaries: a first
139
  temporary `T1` to hold the result of the expression `S(16)`, a second
140
  temporary `T2` to hold the result of the expression `S(23)`, and a third
141
  temporary `T3` to hold the result of the addition of these two
142
  expressions. The temporary `T3` is then bound to the reference `cr`. It
143
  is unspecified whether `T1` or `T2` is created first. On an
144
- implementation where `T1` is created before `T2`, it is guaranteed that
145
- `T2` is destroyed before `T1`. The temporaries `T1` and `T2` are bound
146
- to the reference parameters of `operator+`; these temporaries are
147
- destroyed at the end of the full-expression containing the call to
148
- `operator+`. The temporary `T3` bound to the reference `cr` is destroyed
149
- at the end of `cr`’s lifetime, that is, at the end of the program. In
150
- addition, the order in which `T3` is destroyed takes into account the
151
- destruction order of other objects with static storage duration. That
152
- is, because `obj1` is constructed before `T3`, and `T3` is constructed
153
- before `obj2`, it is guaranteed that `obj2` is destroyed before `T3`,
154
- and that `T3` is destroyed before `obj1`.
155
 
 
2
 
3
  Temporaries of class type are created in various contexts: binding a
4
  reference to a prvalue ([[dcl.init.ref]]), returning a prvalue (
5
  [[stmt.return]]), a conversion that creates a prvalue ([[conv.lval]],
6
  [[expr.static.cast]], [[expr.const.cast]], [[expr.cast]]), throwing an
7
+ exception ([[except.throw]]), and in some initializations (
8
+ [[dcl.init]]). The lifetime of exception objects is described in 
9
+ [[except.throw]]. Even when the creation of the temporary object is
10
+ unevaluated (Clause  [[expr]]) or otherwise avoided ([[class.copy]]),
11
+ all the semantic restrictions shall be respected as if the temporary
12
+ object had been created and later destroyed. This includes
13
+ accessibility ([[class.access]]) and whether it is deleted, for the
14
+ constructor selected and for the destructor. However, in the special
15
+ case of a function call used as the operand of a *decltype-specifier* (
16
+ [[expr.call]]), no temporary is introduced, so the foregoing does not
17
+ apply to the prvalue of any such function call.
 
 
18
 
19
  Consider the following code:
20
 
21
  ``` cpp
22
  class X {
 
77
  default constructor is called to initialize an element of an array. If
78
  the constructor has one or more default arguments, the destruction of
79
  every temporary created in a default argument is sequenced before the
80
  construction of the next array element, if any.
81
 
82
+ The second context is when a reference is bound to a temporary.[^1] The
83
  temporary to which the reference is bound or the temporary that is the
84
  complete object of a subobject to which the reference is bound persists
85
  for the lifetime of the reference except:
86
 
87
  - A temporary bound to a reference member in a constructor’s
88
+ *ctor-initializer* ([[class.base.init]]) persists until the
89
+ constructor exits.
90
  - A temporary bound to a reference parameter in a function call (
91
  [[expr.call]]) persists until the completion of the full-expression
92
  containing the call.
93
  - The lifetime of a temporary bound to the returned value in a function
94
  return statement ([[stmt.return]]) is not extended; the temporary is
 
137
  temporary `T1` to hold the result of the expression `S(16)`, a second
138
  temporary `T2` to hold the result of the expression `S(23)`, and a third
139
  temporary `T3` to hold the result of the addition of these two
140
  expressions. The temporary `T3` is then bound to the reference `cr`. It
141
  is unspecified whether `T1` or `T2` is created first. On an
142
+ implementation where `T1` is created before `T2`, `T2` shall be
143
+ destroyed before `T1`. The temporaries `T1` and `T2` are bound to the
144
+ reference parameters of `operator+`; these temporaries are destroyed at
145
+ the end of the full-expression containing the call to `operator+`. The
146
+ temporary `T3` bound to the reference `cr` is destroyed at the end of
147
+ `cr`’s lifetime, that is, at the end of the program. In addition, the
148
+ order in which `T3` is destroyed takes into account the destruction
149
+ order of other objects with static storage duration. That is, because
150
+ `obj1` is constructed before `T3`, and `T3` is constructed before
151
+ `obj2`, `obj2` shall be destroyed before `T3`, and `T3` shall be
152
+ destroyed before `obj1`.
153