CWG Issue 1696 (original) (raw)

This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-11-05


1696. Temporary lifetime and non-static data member initializers

Section: 6.8.7 [class.temporary]Status: CD4Submitter: Richard SmithDate: 2013-05-31

[Moved to DR at the November, 2014 meeting.]

Presumably a temporary bound to a reference in a non-static data member initializer should be treated analogously with what happens in a_ctor-initializer_, but the current wording of 6.8.7 [class.temporary] paragraph 5 is not clear on this point.

See also issue 1815 for similar questions regarding aggregate initialization.

Proposed resolution (June, 2014):

  1. Add the following after 9.5.2 [dcl.init.aggr] paragraph 7:

If a reference member is initialized from its_brace-or-equal-initializer_ and a potentially-evaluated subexpression thereof is an aggregate initialization that would use that brace-or-equal-initializer, the program is ill-formed. [Example:

struct A; extern A a; struct A { const A& a1 { A{a,a} }; // OK const A& a2 { A{} }; // error }; A a{a,a}; // OK

If an aggregate class C contains a subaggregate...

  1. Delete the first bullet of 6.8.7 [class.temporary] paragraph 5:

The second context is when a reference is bound to a temporary.117 The temporary to which the reference is bound or the temporary that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference except:

  1. Insert the following as a new paragraph after 11.9.3 [class.base.init] paragraph 7:

A temporary expression bound to a reference member in a mem-initializer is ill-formed. [Example:

struct A { A() : v(42) { } // error const int& v; };

—_end example_]

In a non-delegating constructor, if a given potentially constructed subobject...

  1. Insert the following as a new paragraph after 11.9.3 [class.base.init] paragraph 9:

A temporary expression bound to a reference member from a brace-or-equal-initializer is ill-formed. [Example:

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 example_]

In a non-delegating constructor, the destructor for each potentially constructed subobject...

This resolution also resolves issue 1815.