Movatterモバイル変換


[0]ホーム

URL:


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

2025-12-20


1514. Ambiguity between enumeration definition and zero-length bit-field

Section:11.4.10  [class.bit]    Status:C++14    Submitter:John Spicer    Date:2012-07-03

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

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 invalidredefinition ofenum E or a zero-length bit-field of typeenum E (sinceT{} is zero-valued constantexpression). The current Standard does not appear to have a rule todisambiguate the two.

Proposed resolution (October, 2012) [superseded]:

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

...the attributes in thatattribute-specifier-seq arethereafter considered attributes of the enumeration whenever it isnamed.In amember-specification, an ambiguity can arisefrom the similarity between the declaration of an enumeration with anenum-base and the declaration of a zero-length unnamedbit-field of enumeration type. The ambiguity appears as a choicebetween anenum-specifier and amember-declaration for abit-field. The resolution is that a: followingenumidentifier is parsed as part of anenum-base.[Example:

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

end example]

Notes from the April, 2013 meeting:

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

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

Proposed resolution (June, 2013):

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

...the attributes in thatattribute-specifier-seq are thereafterconsidered attributes of the enumeration whenever it is named.A: following “enumidentifier”is parsed as part of anenum-base. [Note: This resolves apotential ambiguity between the declaration of an enumeration with anenum-base and the declaration of an unnamed bit-field ofenumeration type. [Example:

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

end example] —end note]




[8]ページ先頭

©2009-2026 Movatter.jp