Title
Unions with mutable members in constant expressions
Status
cd4
Section
8.20 [expr.const]
Submitter
Richard Smith

Created on 2014-09-16.00:00:00 last changed 40 months ago

Messages

Date: 2015-10-15.00:00:00

[Moved to DR at the October, 2015 meeting.]

Date: 2015-05-15.00:00:00

Proposed resolution (May, 2015):

  1. Add the following bullet after bullet 3.1 of 10.1.5 [dcl.constexpr]:

  2. The definition of a constexpr function shall satisfy the following constraints:

    • it shall not be virtual (13.3 [class.virtual]);

    • for a defaulted copy/move assignment, the class of which it is a member shall not have a mutable subobject that is a variant member;

    • ...

  3. Add the following bullet after bullet 4.1 of 10.1.5 [dcl.constexpr]

  4. The definition of a constexpr constructor shall satisfy the following constraints:

    • the class shall not have any virtual base classes;

    • for a defaulted copy/move constructor, the class shall not have a mutable subobject that is a variant member;

    • ...

Date: 2014-09-16.00:00:00

In an example like

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

The initialization of u2 is not disqualified by the current wording of the Standard because the copy is done via the object representation, not formally involving an lvalue-to-rvalue conversion. A restriction should be added to 8.20 [expr.const] forbidding the evaluation of a defaulted copy/move construction/assignment on a class type that has any variant mutable subobjects.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: dr -> cd4
2015-11-10 00:00:00adminsetmessages: + msg6069
2015-11-10 00:00:00adminsetstatus: ready -> dr
2015-05-25 00:00:00adminsetmessages: + msg5450
2015-05-25 00:00:00adminsetstatus: drafting -> ready
2014-09-16 00:00:00admincreate