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]]),
|
| 8 |
-
[[
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 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
|
| 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`,
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 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 |
|