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

2024-04-18


359. Type definition in anonymous union

Section: 11.5  [class.union]     Status: NAD     Submitter: Al Grant     Date: 31 May 2002

Is this legal? Should it be?

  struct E {
    union {
      struct { int x; } s;
    } v;
  };

One compiler faults a type definition (i.e. of the anonymous struct) since it is in an anonymous union [11.5 [class.union] paragraph 2: "The member-specification of an anonymous union shall only define non-static data members."].

I would suggest that compiler B is correctly interpreting the standard but that this is a defect in the standard. There is no reason to disallow definition of anonymous structs.

Furthermore, is it really necessary to disallow definition of named types in anonymous unions in general, as long as the types do not need fully qualified names for external linkage? Why should this be illegal?

  struct E {
    union {
      typedef int Int;
      struct X { X *next; Int n; } list;
    } v;
  };

Notes from October 2002 meeting:

There was agreement that the standard says such declarations are invalid; therefore this must be considered as an extension. There was general feeling that this extension would not be too useful, though Jason Merrill was sympathetic to the argument. It was also agreed that if this were to be changed it would require careful wording so as not to allow too many cases.

Note (March, 2008):

The Evolution Working Group recommended closing this issue with no further consideration. See paper J16/07-0033 = WG21 N2173.