Title
Ambiguity between enumeration definition and zero-length bit-field
Status
c++14
Section
11.4.10 [class.bit]
Submitter
John Spicer

Created on 2012-07-03.00:00:00 last changed 121 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 9.7.1 [dcl.enum] paragraph 1 as follows:

...the attributes in that attribute-specifier-seq are thereafter considered attributes of the enumeration whenever it is named. A : following “enum identifier” is parsed as part of an enum-base. [Note: This resolves a potential ambiguity between the declaration of an enumeration with an enum-base and the declaration of an unnamed bit-field of enumeration type. [Example:

   struct S {
     enum E : int {};
     enum E : int {};  // error: redeclaration of enumeration
   };

end example] —end note]

Date: 2013-04-15.00:00:00

Notes from the April, 2013 meeting:

The ambiguity does not occur only with an empty set of braces but also when there is a single identifier that could be taken as the name of a constant in a containing scope or the declaration of an enumerator.

The resolution above sounds as if it is to be applied only if an ambiguity occurs; it should instead be always applied.

Date: 2012-10-15.00:00:00

Proposed resolution (October, 2012) [superseded]:

Change 9.7.1 [dcl.enum] paragraph 1 as follows:

...the attributes in that attribute-specifier-seq are thereafter considered attributes of the enumeration whenever it is named. In a member-specification, an ambiguity can arise from the similarity between the declaration of an enumeration with an enum-base and the declaration of a zero-length unnamed bit-field of enumeration type. The ambiguity appears as a choice between an enum-specifier and a member-declaration for a bit-field. The resolution is that a : following enum identifier is parsed as part of an enum-base. [Example:

  struct S {
    enum E : int {};
    enum E : int {};  // error: redeclaration of enumeration
  };

end example]

Date: 2012-07-03.00:00:00

Consider an example like:

  struct S {
    typedef int T;
    enum E : T {};
    enum E : T {};    // #1
  };

The declaration at #1 is ambiguous: it could either be an invalid redefinition of enum E or a zero-length bit-field of type enum E (since T{} is zero-valued constant expression). The current Standard does not appear to have a rule to disambiguate the two.

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: + msg4692
2013-10-14 00:00:00adminsetstatus: tentatively ready -> dr
2013-09-03 00:00:00adminsetmessages: + msg4461
2013-09-03 00:00:00adminsetstatus: drafting -> tentatively ready
2013-05-03 00:00:00adminsetmessages: + msg4337
2013-05-03 00:00:00adminsetstatus: tentatively ready -> drafting
2012-11-03 00:00:00adminsetmessages: + msg4076
2012-11-03 00:00:00adminsetstatus: open -> tentatively ready
2012-07-03 00:00:00admincreate