<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1765</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="1765"></A><H4>1765.
  
Overflow of enumeration used as enumerator value
</H4>
<B>Section: </B>9.8.1&#160; [<A href="https://wg21.link/dcl.enum">dcl.enum</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Canada
 &#160;&#160;&#160;

 <B>Date: </B>2013-09-23<BR><BR>


<A href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3903.html#CA7">N3690 comment
  CA&#160;7<BR></A>

<P>[Moved to DR at the February, 2014 meeting.]</P>

<P>Regarding the value of an enumerator whose enumeration's underlying
type is not fixed, 9.8.1 [<A href="https://wg21.link/dcl.enum#5">dcl.enum</A>] paragraph 5 says,</P>

<BLOCKQUOTE>

the type of the initializing value is the same as the type of the
initializing value of the preceding enumerator unless the incremented value
is not representable in that type, in which case the type is an unspecified
integral type sufficient to contain the incremented value.

</BLOCKQUOTE>

<P>It is not clear how this is to be applied when the preceding
enumerator value is given by an enumerator whose value is the largest
of its enumeration's values, and there is implementation variance on
this point.</P>

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

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

<BLOCKQUOTE>

<P>...If the underlying type is fixed, the type of
each <DEL><I>enumerator</I></DEL> <INS>enumerator</INS> prior to the
closing brace is the underlying type and the <I>constant-expression</I> in
the <I>enumerator-definition</I> shall be a converted constant expression
of the underlying type (7.7 [<A href="https://wg21.link/expr.const">expr.const</A>])<DEL>; if the
initializing value of an enumerator cannot be represented by the underlying
type, the program is ill-formed</DEL>. If the underlying type is not fixed,
the type of each enumerator <INS>prior to the closing brace</INS>
is <DEL>the type of its initializing value</DEL> <INS>determined as
follows</INS>:</P>

<UL>
<LI><P>If an initializer is specified for an enumerator, <DEL>the
initializing value</DEL> <INS>the <I>constant-expression</I> shall be an
integral constant expression (7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]).  If the
expression has unscoped enumeration type, the enumerator has the underlying
type of that enumeration type, otherwise it</INS> has the same type as the
expression <DEL>and the <I>constant-expression</I> shall be an integral
constant expression (7.7 [<A href="https://wg21.link/expr.const">expr.const</A>])</DEL>.</P></LI>

<LI><P>If no initializer is specified for the first enumerator, <DEL>the
initializing value has</DEL> <INS>its type is</INS> an unspecified integral
type.</P></LI>

<LI><P>Otherwise the type of the <DEL>initializing
value</DEL> <INS>enumerator</INS> is the same as <DEL>the
type</DEL> <INS>that</INS> of <DEL>the initializing value of</DEL> the
preceding enumerator unless the incremented value is not representable in
that type, in which case the type is an unspecified integral type
sufficient to contain the incremented value. If no such type exists, the
program is ill-formed.</P></LI>

</UL>

</BLOCKQUOTE>

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