Skip to content

Commit e93d9e0

Browse files
committed
Merge 2017-07 CWG Motion 3
2 parents 9acd179 + 526e493 commit e93d9e0

File tree

7 files changed

+82
-11
lines changed

7 files changed

+82
-11
lines changed

source/compatibility.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@
12941294
\item using \tcode{operator==} to compare to \tcode{false} or \tcode{true};
12951295
\item returning a value from a function with a return type of \tcode{bool};
12961296
\item initializing members of type \tcode{bool} via aggregate initialization;
1297-
\item initializing a \tcode{const bool\&} which would bind to a temporary.
1297+
\item initializing a \tcode{const bool\&} which would bind to a temporary object.
12981298
\end{itemize}
12991299

13001300
\ref{ios::failure}

source/expressions.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
\begin{note}
239239
If the expression is an lvalue of
240240
class type, it must have a volatile copy constructor to initialize the
241-
temporary that is the result object of the lvalue-to-rvalue
241+
temporary object that is the result object of the lvalue-to-rvalue
242242
conversion. \end{note}
243243
The glvalue expression is evaluated and its value is discarded.
244244

source/lib-intro.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,8 @@
26022602
and thus is not covered by the previous sentence. \end{note} \begin{note} If a program casts
26032603
an lvalue to an xvalue while passing that lvalue to a library function (e.g. by calling the function
26042604
with the argument \tcode{std::move(x)}), the program
2605-
is effectively asking that function to treat that lvalue as a temporary. The implementation
2605+
is effectively asking that function to treat that lvalue as a temporary object.
2606+
The implementation
26062607
is free to optimize away aliasing checks which might be needed if the argument was
26072608
an lvalue. \end{note}
26082609
\end{itemize}

source/numerics.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6745,7 +6745,7 @@
67456745
by the generalized subscript operators.\footnote{The intent is to specify
67466746
an array template that has the minimum functionality
67476747
necessary to address aliasing ambiguities and the proliferation of
6748-
temporaries.
6748+
temporary objects.
67496749
Thus, the
67506750
\tcode{valarray}
67516751
template is neither a

source/overloading.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,8 @@
12111211
the non-explicit conversion functions of
12121212
\tcode{S}
12131213
and its base classes are considered.
1214-
When initializing a temporary to be bound to the first parameter of a
1215-
constructor
1214+
When initializing a temporary object~(\ref{class.mem})
1215+
to be bound to the first parameter of a constructor
12161216
where the parameter is of type
12171217
``reference to possibly \cv-qualified \tcode{T}''
12181218
and the constructor is

source/special.tex

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,83 @@
524524

525525
\pnum
526526
The third context is when a reference is bound to a
527-
temporary.\footnote{The same rules apply to initialization of an
527+
temporary object.\footnote{The same rules apply to initialization of an
528528
\tcode{initializer_list} object~(\ref{dcl.init.list}) with its
529529
underlying temporary array.}
530-
The temporary to which the reference is bound or the temporary
530+
The temporary object to which the reference is bound or the temporary object
531531
that is the complete object of a subobject to which the reference is bound
532-
persists for the lifetime of the reference except:
532+
persists for the lifetime of the reference if the glvalue
533+
to which the reference is bound
534+
was obtained through one of the following:
535+
\begin{itemize}
536+
\item
537+
a temporary materialization conversion~(\ref{conv.rval}),
538+
\item
539+
\tcode{(} \grammarterm{expression} \tcode{)},
540+
where \grammarterm{expression} is one of these expressions,
541+
\item
542+
subscripting~(\ref{expr.sub}) of an array operand,
543+
where that operand is one of these expressions,
544+
\item
545+
a class member access~(\ref{expr.ref}) using the \tcode{.} operator
546+
where the left operand is one of these expressions and
547+
the right operand designates a non-static data member of non-reference type,
548+
\item
549+
a pointer-to-member operation~(\ref{expr.mptr.oper}) using the \tcode{.*} operator
550+
where the left operand is one of these expressions and
551+
the right operand is a pointer to data member of non-reference type,
552+
\item
553+
a \tcode{const_cast}~(\ref{expr.const.cast}),
554+
\tcode{static_cast}~(\ref{expr.static.cast}),
555+
\tcode{dynamic_cast}~(\ref{expr.dynamic.cast}), or
556+
\tcode{reinterpret_cast}~(\ref{expr.reinterpret.cast})
557+
converting, without a user-defined conversion,
558+
a glvalue operand that is one of these expressions
559+
to a glvalue that refers
560+
to the object designated by the operand, or
561+
to its complete object or a subobject thereof,
562+
\item
563+
a conditional expression~(\ref{expr.cond}) that is a glvalue
564+
where the second or third operand is one of these expressions, or
565+
\item
566+
a comma expression~(\ref{expr.comma}) that is a glvalue
567+
where the right operand is one of these expressions.
568+
\end{itemize}
569+
\begin{example}
570+
\begin{codeblock}
571+
template<typename T> using id = T;
572+
573+
int&& a = id<int[3]>{1, 2, 3}[i]; // temporary array has same lifetime as \tcode{a}
574+
const int& b = static_cast<const int&>(0); // temporary \tcode{int} has same lifetime as \tcode{b}
575+
int&& c = cond ? id<int[3]>{1, 2, 3}[i] : static_cast<int&&>(0);
576+
// exactly one of the two temporaries is lifetime-extended
577+
\end{codeblock}
578+
\end{example}
579+
\begin{note}
580+
An explicit type conversion~(\ref{expr.type.conv}, \ref{expr.cast})
581+
is interpreted as
582+
a sequence of elementary casts,
583+
covered above.
584+
\begin{example}
585+
\begin{codeblock}
586+
const int& x = (const int&)1; // temporary for value 1 has same lifetime as x
587+
\end{codeblock}
588+
\end{example}
589+
\end{note}
590+
\begin{note}
591+
If a temporary object has a reference member initialized by another temporary object,
592+
lifetime extension applies recursively to such a member's initializer.
593+
\begin{example}
594+
\begin{codeblock}
595+
struct S {
596+
const int& m;
597+
};
598+
const S& s = S{1}; // both \tcode{S} and \tcode{int} temporaries have lifetime of \tcode{s}
599+
\end{codeblock}
600+
\end{example}
601+
\end{note}
533602

603+
The exceptions to this lifetime rule are:
534604
\begin{itemize}
535605
\item A temporary object bound to a reference parameter in a function call~(\ref{expr.call})
536606
persists until the completion of the full-expression containing the call.
@@ -541,7 +611,7 @@
541611
\begin{codeblock}
542612
struct S { int mi; const std::pair<int,int>& mp; };
543613
S a { 1, {2,3} };
544-
S* p = new S{ 1, {2,3} }; // Creates dangling reference
614+
S* p = new S{ 1, {2,3} }; // creates dangling reference
545615
\end{codeblock}
546616
\end{example} \begin{note} This may introduce a dangling reference, and implementations should issue a warning in such a case. \end{note}
547617
\end{itemize}

source/utilities.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10585,7 +10585,7 @@
1058510585
\pnum\effects Equivalent to \tcode{weak_ptr(r).swap(*this)}.
1058610586

1058710587
\pnum\remarks The implementation may meet the effects (and the
10588-
implied guarantees) via different means, without creating a temporary.
10588+
implied guarantees) via different means, without creating a temporary object.
1058910589

1059010590
\pnum\returns \tcode{*this}.
1059110591
\end{itemdescr}

0 commit comments

Comments
 (0)