Skip to content

Commit

Permalink
CWG1696 Temporary lifetime and non-static data member initializers
Browse files Browse the repository at this point in the history
Also fixes CWG1815.
  • Loading branch information
Dawn Perchik authored and zygoloid committed Nov 18, 2014
1 parent 7a88dca commit c93a904
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
17 changes: 17 additions & 0 deletions source/declarators.tex
Expand Up @@ -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,
Expand Down
31 changes: 28 additions & 3 deletions source/special.tex
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}).
Expand Down

0 comments on commit c93a904

Please sign in to comment.