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

2023-01-15


1480. Constant initialization via non-constant temporary

Section: 7.7  [expr.const]     Status: CD3     Submitter: Daniel Krügler     Date: 2012-03-17

The following initializations appear to be well-formed:

  struct C {
   int m;
   constexpr C(int m ) : m{m} {};
   constexpr int get() { return m; };
  };

  C&& rr = C{1};
  constexpr int k1 = rr.get();

  const C& cl = C{1};
  constexpr int k2 = cl.get();

They appear to fall under the bullet of 7.7 [expr.const] paragraph 2,

The problem in this example is that the referenced temporary object is not a constant, so it would be well-defined for intervening code to modify its value before it was used in the later initialization.

Additional note (February, 2013):

The intent is that non-const references to temporaries should be allowed within constant expressions, e.g., across constexpr function calls, but not as the result of a constant expression.

Proposed resolution (April, 2013):

This issue was rendered moot by paper N3652, adopted at the April, 2013 meeting.