Movatterモバイル変換


[0]ホーム

URL:


Issue 2268 - WG21 CWG Issues
Title
Unions with mutable members in constant expressions revisited
Status
c++17
Section
9.2.6 [dcl.constexpr]
Submitter
Richard Smith

Created on2016-05-26.00:00:00 last changed96 months ago

Messages

msg6160 (view)
Date: 2017-02-15.00:00:00

Proposed resolution (February, 2017):

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

  2. Aconditional-expressione is acore constantexpression unless the evaluation ofe , following the rules ofthe abstract machine (6.10.1 [intro.execution]), would evaluate one of thefollowing expressions:

    • ...

    • an lvalue-to-rvalue conversion (7.3.2 [conv.lval]) that isapplied to a glvalue that refers to a non-active member of a union or asubobject thereof;

    • an invocation of an implicitly-defined copy/move constructoror copy/move assignment operator for a union whose active member (if any)is mutable, unless the lifetime of the union object began within theevaluation ofe;

    • ...

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

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

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

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

msg5791 (view)
Date: 2017-02-15.00:00:00

[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 farby making the copy and move operations ofU non-constexpr.This breaks reasonable code such as:

  constexpr int f() {    U u = {1};    U v = u;    return v.a;  }
History
DateUserActionArgs
2018-02-27 00:00:00adminsetmessages: +msg6160
2018-02-27 00:00:00adminsetstatus: open -> c++17
2016-05-26 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp