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


716. Specifications that should apply only to non-static union data members

Section: 11.5  [class.union]     Status: CD2     Submitter: Mike Miller     Date: 17 September, 2008

[Voted into WP at July, 2009 meeting.]

Unions are no longer forbidden to have static data members; however, much of the wording of 11.5 [class.union] (and possibly other places in the Standard) is still written with that assumption and refers only to “data members” when clearly non-static data members are in view. From paragraph 1, for example:

In a union, at most one of the data members can be active at any time... The size of a union is sufficient to contain the largest of its data members...

Proposed resolution (March, 2009):

  1. Change the footnote in 6.8.5 [basic.type.qualifier] paragraph 1 as follows:

  2. The same representation and alignment requirements are meant to imply interchangeability as arguments to functions, return values from functions, and non-static data members of unions.
  3. Change 7.2.1 [basic.lval] bullet 15.6 as follows:

  4. Change 7.6.9 [expr.rel] bullet 2.5 as follows:

  5. Change 9.12.2 [dcl.align] paragraph 8 as follows:

  6. [Note: the alignment of a union type can be strengthened by applying the alignment attribute to any non-static data member of the union. —end note]
  7. Change 9.4.2 [dcl.init.aggr] paragraph 15 as follows:

  8. When a union is initialized with a brace-enclosed initializer, the braces shall only contain an initializer-clause for the first non-static data member of the union...
  9. Change 11.5 [class.union] paragraph 1 as follows:

  10. In a union, at most one of the non-static data members can be active at any time, that is, the value of at most one of the non-static data members can be stored in a union at any time. [Note: one special guarantee is made in order to simplify the use of unions: If a standard-layout union contains several standard-layout structs that share a common initial sequence (11.4 [class.mem]), and if an object of this standard-layout union type contains one of the standard-layout structs, it is permitted to inspect the common initial sequence of any of standard-layout struct members; see 11.4 [class.mem]. —end note] The size of a union is sufficient to contain the largest of its non-static data members. Each non-static data member is allocated as if it were the sole member of a struct. A union can have...