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

2024-04-18


2408. Temporaries and previously-initialized elements in aggregate initialization

Section: 9.4.2  [dcl.init.aggr]     Status: NAD     Submitter: Daveed Vandevoorde     Date: 2019-03-13

There is implementation divergence with respect to an example like:

  constexpr int f(int &r) { r *= 9; return r - 12; }
  struct A { int &&temporary; int x; int y; };

  constexpr A a1 = { 6, f(a1.temporary), a1.temporary }; // #1 

Some implementations accept this code and others say that a1.temporary is not a constant expression in the initializer at #1.

Rationale (July, 2019)

The example is valid; the constant evaluation is the entire initialization constexpr A a1, thus the temporary bound to a1.temporary started its lifetime within the constant evaluation.