<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2629</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="2629"></A><H4>2629.
  
Variables of floating-point type as <TT>switch</TT> conditions
</H4>
<B>Section: </B>8.5.3&#160; [<A href="https://wg21.link/stmt.switch">stmt.switch</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Jim X
 &#160;&#160;&#160;

 <B>Date: </B>2022-09-07<BR>


<P>[Accepted as a DR at the November, 2022 meeting.]</P>

<P>Consider:</P>

<PRE>
switch(float v = 0) {
  case 0: ;
}
</PRE>

<P>Subclause 8.1 [<A href="https://wg21.link/stmt.pre#5">stmt.pre</A>] paragraph 5 specifies:</P>

<BLOCKQUOTE>

... The value of a <I>condition</I> that is an initialized declaration in a
<TT>switch</TT> statement is the value of the declared variable if it has
integral or enumeration type, or of that variable implicitly converted
to integral or enumeration type otherwise. ...

</BLOCKQUOTE>

<P>That appears to permit variables of floating-point type, whose
value can be converted to integral type.  In
contrast, <I>expression</I>s of floating-point type are prohibited by
8.5.3 [<A href="https://wg21.link/stmt.switch#2">stmt.switch</A>] paragraph 2:</P>

<BLOCKQUOTE>

The condition shall be of integral type, enumeration type, or class type. ...

</BLOCKQUOTE>

<P><U>Possible resolution [SUPERSEDED]:</U></P>

<P>Change in 8.1 [<A href="https://wg21.link/stmt.pre#5">stmt.pre</A>] paragraph 5 as follows:</P>

<BLOCKQUOTE>

... The value of a <I>condition</I> that is an initialized declaration in a
<TT>switch</TT> statement is the value of the declared variable if it
has integral or enumeration type, or of that variable implicitly
converted to integral or enumeration type <INS>if it has class
type;</INS> otherwise <INS>the program is ill-formed</INS>. ...

</BLOCKQUOTE>

<P><B>CWG telecon 2022-10-21:</B></P>

<P>Rewording is needed.</P>

<P><B>Proposed resolution (approved by CWG 2022-11-09):</B></P>

<OL>

<LI>

<P>Change in 8.1 [<A href="https://wg21.link/stmt.pre#5">stmt.pre</A>] paragraph 5 as follows:</P>

<BLOCKQUOTE>

... <DEL>The value of a <I>condition</I> that is an initialized declaration in a
<TT>switch</TT> statement is the value of the declared variable if it
has integral or enumeration type, or of that variable implicitly
converted to integral or enumeration type otherwise.</DEL> ...

</BLOCKQUOTE>

</LI>

<LI>

<P>Change in 8.5.3 [<A href="https://wg21.link/stmt.switch#2">stmt.switch</A>] paragraph 2 as follows:</P>

<BLOCKQUOTE>

<INS>The value of a <I>condition</I> that is an initialized
declaration is the value of the declared variable, or the value of
the <I>expression</I> otherwise.</INS> The <INS>value of the</INS>
condition shall be of integral type, enumeration type, or class
type. If of class type, the condition is contextually implicitly
converted (7.3 [<A href="https://wg21.link/conv">conv</A>]) to an integral or enumeration
type. If the (possibly converted) type is subject to integral
promotions (7.3.7 [<A href="https://wg21.link/conv.prom">conv.prom</A>]), the condition is converted to
the promoted type. ...

</BLOCKQUOTE>

</LI>

</OL>

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