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

2024-03-20


1375. Reference to anonymous union?

Section: 11.5  [class.union]     Status: CD3     Submitter: Daveed Vandevoorde     Date: 2011-08-16

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

According to 11.5 [class.union] paragraph 7,

A union for which objects or pointers are declared is not an anonymous union.

This should also apply to references, which are now possible because decltype allows writing an initializer for an unnamed union:

    char buf[100];
    union {
      int i;
    } &r = (decltype(r)) buf;

Proposed resolution (February, 2012):

Change 11.5 [class.union] paragraph 7:

A union for which objects, or pointers, or references are declared is not an anonymous union. [Example:

  void f() {
    union { int aa; char* p; } obj, *ptr = &obj;
    aa = 1;      // error
    ptr->aa = 1; // OK
  }