diff --git a/source/declarators.tex b/source/declarators.tex index dd0af2aaf1..cd40450a87 100644 --- a/source/declarators.tex +++ b/source/declarators.tex @@ -2980,6 +2980,23 @@ \tcode{a} and \tcode{b} have the same value \exitexample +\pnum +If a reference member is initialized from its \grammarterm{brace-or-equal-initializer} +and a potentially-evaluated subexpression thereof is an aggregate +initialization that would use that \grammarterm{brace-or-equal-initializer}, +the program is ill-formed. +\enterexample +\begin{codeblock} + struct A; + extern A a; + struct A { + const A& a1 { A{a,a} }; // OK + const A& a2 { A{} }; // error + }; + A a{a,a}; // OK +\end{codeblock} +\exitexample + \pnum If an aggregate class \tcode{C} contains a subaggregate member \tcode{m} that has no members for purposes of aggregate initialization, diff --git a/source/special.tex b/source/special.tex index eb38200f70..a8cf0715d9 100644 --- a/source/special.tex +++ b/source/special.tex @@ -482,9 +482,7 @@ persists for the lifetime of the reference except: \begin{itemize} -\item A temporary bound to a reference member in a constructor's \grammarterm{ctor-initializer}~(\ref{class.base.init}) persists until the constructor exits. - -\item A temporary bound to a reference parameter in a function call~(\ref{expr.call}) +\item A temporary object bound to a reference parameter in a function call~(\ref{expr.call}) persists until the completion of the full-expression containing the call. \item The lifetime of a temporary bound to the returned value in a function return statement~(\ref{stmt.return}) is not extended; the temporary is destroyed at the end of the full-expression in the return statement. @@ -1691,6 +1689,18 @@ a virtual base class is ignored during execution of a constructor of any class that is not the most derived class. +\pnum +A temporary expression bound to a reference member in a \grammarterm{mem-initializer} +is ill-formed. +\enterexample +\begin{codeblock} + struct A { + A() : v(42) { } // error + const int& v; + }; +\end{codeblock} +\exitexample + \pnum In a non-delegating constructor, if a given potentially constructed subobject is not designated by a @@ -1781,6 +1791,21 @@ will not take place. \exitexample +\pnum +A temporary expression bound to a reference member from a +\grammarterm{brace-or-equal-initializer} is ill-formed. +\enterexample Given +\begin{codeblock} + struct A { + A() = default; // OK + A(int v) : v(v) { } // OK + const int& v = 42; // OK + }; + A a1; // error: ill-formed binding of temporary to reference + A a2(1); // OK, unfortunately +\end{codeblock} +\exitexample + \pnum In a non-delegating constructor, the destructor for each potentially constructed subobject of class type is potentially invoked~(\ref{class.dtor}).