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

2024-11-11


2268. Unions with mutable members in constant expressions revisited

Section: 9.2.6  [dcl.constexpr]     Status: C++17     Submitter: Richard Smith     Date: 2016-05-26

[Adopted at the February/March, 2017 meeting.]

Issue 2004 concerns this example:

  union U { int a; mutable int b; };
  constexpr U u1 = {1};
  int k = (u1.b = 2);
  constexpr U u2 = u1; 

Clearly this must be ill-formed. But issue 2004 goes too far by making the copy and move operations of U non-constexpr. This breaks reasonable code such as:

  constexpr int f() {
    U u = {1};
    U v = u;
    return v.a;
  } 

Proposed resolution (February, 2017):

  1. Add the following as a new bullet following 7.7 [expr.const] bullet 2.8

  2. A conditional-expression e is a core constant expression unless the evaluation of e , following the rules of the abstract machine (6.9.1 [intro.execution]), would evaluate one of the following expressions:

  3. Delete bullet 3.2 in 9.2.6 [dcl.constexpr]:

  4. Delete bullet 4.2 in 9.2.6 [dcl.constexpr]: