This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
[Voted into the WP at the July, 2017 meeting as document P0727R0.]
The Standard is insufficiently precise in dealing with temporaries. It is not always clear when the term “temporary” is referring to an expression whose result is a prvalue and when it is referring to a temporary object.
(See also issue 1568.)
Proposed resolution (February, 2014) [SUPERSEDED]:
The resolution is contained in document N3918.
This resolution also resolves issues 1651 and 1893.
Additional note, November, 2014:
Concerns have been raised that the meaning of “corresponding temporary object” is not clear enough in the proposed wording. In addition, N3918 says that it resolves issue 1300, but that issue is 1) marked as a duplicate of issue 914 and 2) the subject of continuing deliberations in EWG. This issue is being returned to "review" status to allow CWG to address these concerns.
Proposed resolution (March, 2017):
Change Clause 7 [expr] paragraph 12 as follows:
...is applied. [Note: If the expression is an lvalue of class type, it must have a volatile copy constructor to initialize the temporary object that is the result object of the lvalue-to-rvalue conversion. —end note] The glvalue expression...
Change 6.7.7 [class.temporary] paragraph 6 as follows:
The third context is when a reference is bound to a temporary object.116 The temporary object to which the reference is bound or the temporary object that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference if the glvalue referring to the temporary object was obtained through one of the following:
a temporary materialization conversion (7.3.5 [conv.rval]),
( expression ), where expression is one of these expressions,
subscripting (7.6.1.2 [expr.sub]) of an array operand, where that operand is one of these expressions,
a class member access (7.6.1.5 [expr.ref]) using the . operator where the left operand is one of these expressions and the right operand designates a non-static data member of non-reference type,
a pointer-to-member operation (7.6.4 [expr.mptr.oper]) using the .* operator where the left operand is one of these expressions and the right operand is a pointer to data member of non-reference type,
a const_cast (7.6.1.11 [expr.const.cast], static_cast (7.6.1.9 [expr.static.cast]), dynamic_cast (7.6.1.7 [expr.dynamic.cast]), or reinterpret_cast (7.6.1.10 [expr.reinterpret.cast]) converting a glvalue operand that is one of these expressions to a glvalue referring to that operand,
a conditional expression (7.6.16 [expr.cond]) that is a glvalue where the second or third operand is one of these expressions, or
a comma expression (7.6.20 [expr.comma]) that is a glvalue where the right operand is one of these expressions.
[Example:
template<typename T> using id = T; int&& a = id<int[3]>{1, 2, 3}[i]; // temporary array has same lifetime as a const int& b = static_cast<const int&>(0); // temporary int has same lifetime as b int&& c = cond ? id<int[3]>{1, 2, 3}[i] : static_cast<int&&>(0); // exactly one of the two temporaries is lifetime-extended—end example] [Note: If a temporary object has a reference member initialized by another temporary object, lifetime extension applies recursively to such a member's initializer. [Example:
struct S { const int& m; }; const S& s = S{1}; // both S and int temporaries have lifetime of s—end example] —end note]
exceptThe exceptions to this lifetime rule are:
A temporary object bound to a reference parameter...
Change 12.2.2.5 [over.match.copy] bullet 1.2 as follows:
When the type of the initializer expression is a class type “cv S”, the non-explicit conversion functions of S and its base classes are considered. When initializing a temporary object (11.4 [class.mem]) to be bound to the first parameter of a constructor...
Change 16.4.5.9 [res.on.arguments] bullet 1.3 as follows:
...[Note: If a program casts an lvalue to an xvalue while passing that lvalue to a library function (e.g. by calling the function with the argument std::move(x)), the program is effectively asking that function to treat that lvalue as a temporary object. The implementation is free...
Change 20.3.2.3.4 [util.smartptr.weak.assign] paragraph 2 as follows:
Remarks: The implementation may meet the effects (and the implied guarantees) via different means, without creating a temporary object.
Change the footnote in 28.6.2.1 [template.valarray.overview] paragraph 1 as follows:
...generalized subscript operators. [Footnote: The intent is to specify an array template that hass the minimum functionality necessary to address aliasing ambiguities and the proliferation oftemporariestemporary objects. Thus... —end footnote]
Change the last bullet of C.6.16 [diff.cpp03.input.output] as follows:
initializing a const bool & which would bind to a temporary object.
This resolution also resolves issues 943 and 1076.