Title
constexpr initialization and nested anonymous unions
Status
c++14
Section
9.2.6 [dcl.constexpr]
Submitter
Daveed Vandvoorde

Created on 2012-11-16.00:00:00 last changed 81 months ago

Messages

Date: 2013-09-15.00:00:00

[Moved to DR at the September, 2013 meeting.]

Date: 2013-06-15.00:00:00

Proposed resolution (June, 2013):

Change 11.5 [class.union] paragraph 5 as follows:

...The member-specification of an anonymous union shall only define non-static data members. [Note: Nested types, anonymous unions, and functions cannot be declared within an anonymous union. —end note] The names of the members...
Date: 2013-03-15.00:00:00

Additional note (March, 2013):

It is not clear whether this example violates 11.5 [class.union] paragraph 5:

The member-specification of an anonymous union shall only define non-static data members. [Note: Nested types and functions cannot be declared within an anonymous union. —end note]

Is a nested anonymous union a “non-static data member” or a “nested type?”

See also issues 57, 1460, 1562, 1587, 1621, and 1623.

Date: 2012-11-16.00:00:00

After the resolution of issue 1359, one of the requirements for constexpr constructors is:

if the class is a non-empty union, or for each non-empty anonymous union member of a non-union class, exactly one non-static data member shall be initialized;

This wording does not appear to handle nested anonymous unions. For example:

  struct S {
    union {
      union {
        int x = 1;
        float f;
      };
      void *p = nullptr;
    };
  }; 

Clearly here both S::x and S::p are initialized, but that does not appear to violate the new constraint.

History
Date User Action Args
2014-11-24 00:00:00adminsetstatus: drwp -> c++14
2014-03-03 00:00:00adminsetstatus: dr -> drwp
2013-10-14 00:00:00adminsetmessages: + msg4684
2013-10-14 00:00:00adminsetstatus: tentatively ready -> dr
2013-09-03 00:00:00adminsetmessages: + msg4455
2013-09-03 00:00:00adminsetstatus: drafting -> tentatively ready
2013-05-03 00:00:00adminsetstatus: open -> drafting
2013-03-18 00:00:00adminsetmessages: + msg4273
2012-11-16 00:00:00admincreate