<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1514</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="1514"></A><H4>1514.
  
Ambiguity between enumeration definition and zero-length bit-field
</H4>
<B>Section: </B>11.4.10&#160; [<A href="https://wg21.link/class.bit">class.bit</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++14
 &#160;&#160;&#160;

 <B>Submitter: </B>John Spicer
 &#160;&#160;&#160;

 <B>Date: </B>2012-07-03<BR>


<P>[Moved to DR at the September, 2013 meeting.]</P>

<P>Consider an example like:</P>

<PRE>
  struct S {
    typedef int T;
    enum E : T {};
    enum E : T {};    //<SPAN CLASS="cmnt"> #1</SPAN>
  };
</PRE>

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

<P><B>Proposed resolution (October, 2012) [superseded]:</B></P>

<P>Change 9.8.1 [<A href="https://wg21.link/dcl.enum#1">dcl.enum</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

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

<PRE>
<INS>  struct S {
    enum E : int {};
    enum E : int {};  //<SPAN CLASS="cmnt"> error: redeclaration of enumeration</SPAN>
  };</INS>
</PRE>

<P><INS>&#8212;<I>end example</I>]</INS></P>

</BLOCKQUOTE>

<P><B>Notes from the April, 2013 meeting:</B></P>

<P>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.</P>

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

<P><B>Proposed resolution (June, 2013):</B></P>

<P>Change 9.8.1 [<A href="https://wg21.link/dcl.enum#1">dcl.enum</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

<P>...the attributes in that <I>attribute-specifier-seq</I> are thereafter
considered attributes of the enumeration whenever it is named.
<INS>A <TT>:</TT> following &#8220;<TT>enum</TT> <I>identifier</I>&#8221;
is parsed as part of an <I>enum-base</I>.  [<I>Note:</I> This resolves a
potential ambiguity between the declaration of an enumeration with an
<I>enum-base</I> and the declaration of an unnamed bit-field of
enumeration type. [<I>Example:</I></INS>
</P>

<PRE>
<INS>   struct S {
     enum E : int {};
     enum E : int {};  //<SPAN CLASS="cmnt"> error: redeclaration of enumeration</SPAN>
   };</INS>
</PRE>

<P><INS>&#8212;<I>end example</I>] &#8212;<I>end note</I>]</INS></P>

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
