<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1094</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="1094"></A><H4>1094.
  
Converting floating-point values to scoped enumeration types
</H4>
<B>Section: </B>7.6.1.9&#160; [<A href="https://wg21.link/expr.static.cast">expr.static.cast</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Daniel Kr&#252;gler
 &#160;&#160;&#160;

 <B>Date: </B>2010-07-17<BR>


<P>[Voted into the WP at the March, 2011 meeting.]</P>



<P>According to 9.8.1 [<A href="https://wg21.link/dcl.enum#10">dcl.enum</A>] paragraph 10,</P>

<BLOCKQUOTE>

An expression of arithmetic or enumeration type can be
converted to an enumeration type explicitly.

</BLOCKQUOTE>

<P>However, 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#10">expr.static.cast</A>] paragraph 10 says only,</P>

<BLOCKQUOTE>

A value of integral or enumeration type can be explicitly
converted to an enumeration type.

</BLOCKQUOTE>

<P>This omits floating-point values.  Presumably unscoped
enumeration types are covered by paragraph 7,</P>

<BLOCKQUOTE>

The inverse of any standard conversion sequence (
7.3 [<A href="https://wg21.link/conv">conv</A>]), other than the lvalue-to-rvalue
(7.3.2 [<A href="https://wg21.link/conv.lval">conv.lval</A>]), array-to- pointer (7.3.3 [<A href="https://wg21.link/conv.array">conv.array</A>]), function-to-pointer (7.3.4 [<A href="https://wg21.link/conv.func">conv.func</A>]), and boolean (7.3.14 [<A href="https://wg21.link/conv.fctptr">conv.fctptr</A>])
conversions, can be performed explicitly using
<TT>static_cast</TT>.

</BLOCKQUOTE>

<P>because 7.3.11 [<A href="https://wg21.link/conv.fpint#2">conv.fpint</A>] paragraph 2 allows an
unscoped enumeration value to be implicitly converted to a
floating point type.  (Although that also covers the integral
types, so it's not clear why they would be mentioned
specifically in 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#10">expr.static.cast</A>] paragraph 10.)
However, this should presumably say &#8220;arithmetic&#8221;
instead of &#8220;integral&#8221; to match the statement in
9.8.1 [<A href="https://wg21.link/dcl.enum#10">dcl.enum</A>] paragraph 10.</P>

<P><B>Proposed resolution (November, 2010):</B></P>

<OL>
<LI><P>Change 7.6.1.9 [<A href="https://wg21.link/expr.static.cast#10">expr.static.cast</A>] paragraph 10 as follows:</P></LI>

<BLOCKQUOTE>

A value of integral or enumeration type can be explicitly converted to
an enumeration type.  The value is unchanged if the original value is
within the range of the enumeration values (9.8.1 [<A href="https://wg21.link/dcl.enum">dcl.enum</A>]). Otherwise, the resulting <DEL>enumeration</DEL> value is
unspecified <INS>(and might not be in that range). A value of
floating-point type can also be converted to an enumeration type. The
resulting value is the same as converting the original value to the
underlying type of the enumeration (7.3.11 [<A href="https://wg21.link/conv.fpint">conv.fpint</A>]), and
subsequently to the enumeration type</INS>.

</BLOCKQUOTE>

<LI><P>Add the following footnote to the end of 9.8.1 [<A href="https://wg21.link/dcl.enum#7">dcl.enum</A>] paragraph 7:
</P></LI>

<BLOCKQUOTE>

...If the <I>enumerator-list</I> is empty, the values of the
enumeration are as if the enumeration had a single enumerator with
value 0. <INS>[<I>Footnote:</I> This set of values is used to define
promotion and conversion semantics for the enumeration type; it does
not exclude an expression of enumeration type from having a value that
falls outside this range. &#8212;<I>end footnote</I>]</INS>

</BLOCKQUOTE>

<LI><P>Delete 9.8.1 [<A href="https://wg21.link/dcl.enum#10">dcl.enum</A>] paragraph 10:</P></LI>

<BLOCKQUOTE>

<DEL>An expression of arithmetic or enumeration type can be converted
to an enumeration type explicitly.  The value is unchanged if it is in
the range of enumeration values of the enumeration type; otherwise the
resulting enumeration value is unspecified.</DEL>

</BLOCKQUOTE>

</OL>

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