<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2039</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="2039"></A><H4>2039.
  
Constant conversions to <TT>bool</TT>
</H4>
<B>Section: </B>14.5&#160; [<A href="https://wg21.link/except.spec">except.spec</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD4
 &#160;&#160;&#160;

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2014-11-09<BR>


<P>[Adopted at the February, 2016 meeting.]</P>



<P>According to 14.5 [<A href="https://wg21.link/except.spec#1">except.spec</A>] paragraph 1,</P>

<BLOCKQUOTE>

In a <I>noexcept-specification</I>,
the <I>constant-expression</I>, if supplied, shall be a
constant expression (7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]) that is
contextually converted to bool (
7.3 [<A href="https://wg21.link/conv">conv</A>]).

</BLOCKQUOTE>

<P>This allows the expression to have any type that can be converted
to <TT>bool</TT>, which is too lenient; it should instead say something
like &#8220;a converted constant expression of type <TT>bool</TT>
(7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]).&#8221;  This would include the
conversion to <TT>bool</TT> in the determination of whether the
expression is constant or not and would also disallow narrowing
conversions.</P>

<P>A similar consideration applies to <TT>static_assert</TT>
(9.1 [<A href="https://wg21.link/dcl.pre#6">dcl.pre</A>] paragraph 6), which should probably be
recast to something like, &#8220;an expression that is a constant
expression (7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]) after contextual conversion
to <TT>bool</TT> (7.3 [<A href="https://wg21.link/conv">conv</A>]).&#8221;</P>

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

<OL>
<LI><P>Change 7.7 [<A href="https://wg21.link/expr.const#4">expr.const</A>] paragraph 4 as follows:</P></LI>

<BLOCKQUOTE>

...binds directly. [<I>Note:</I> such expressions may be used in new
expressions (7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>]), as case expressions
(8.5.3 [<A href="https://wg21.link/stmt.switch">stmt.switch</A>]), as enumerator initializers if the underlying
type is fixed (9.8.1 [<A href="https://wg21.link/dcl.enum">dcl.enum</A>]), as array bounds
(9.3.4.5 [<A href="https://wg21.link/dcl.array">dcl.array</A>]), and as non-type template arguments
(13.4 [<A href="https://wg21.link/temp.arg">temp.arg</A>]). &#8212;<I>end note</I>] <INS>A <I>contextually
converted constant expression of type <TT>bool</TT></I> is an expression,
contextually converted to <TT>bool</TT> (7.3 [<A href="https://wg21.link/conv">conv</A>]),
where the converted expression is a constant expression and the conversion
sequence contains only the conversions above.</INS>

</BLOCKQUOTE>

<LI><P>Change 9.1 [<A href="https://wg21.link/dcl.pre#6">dcl.pre</A>] paragraph 6 as follows:</P></LI>

<BLOCKQUOTE>

In a <I>static_assert-declaration</I><INS>,</INS>
the <I>constant-expression</I> shall be a <INS>contextually converted</INS>
constant expression <INS>of type <TT>bool</TT></INS>
(7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]) <DEL>that can be contextually converted
to <TT>bool</TT> (7.3 [<A href="https://wg21.link/conv">conv</A>])</DEL>. If the value of the
expression when so converted is <TT>true</TT>...

</BLOCKQUOTE>

<LI><P>Change 14.5 [<A href="https://wg21.link/except.spec#1">except.spec</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

In a <I>noexcept-specification</I>, the <I>constant-expression</I>, if
supplied, shall be a <INS>contextually converted</INS> constant expression
<INS>of type <TT>bool</TT></INS> (7.7 [<A href="https://wg21.link/expr.const">expr.const</A>]) <DEL>that is
contextually converted to <TT>bool</TT> (
7.3 [<A href="https://wg21.link/conv">conv</A>])</DEL>. A <TT>(</TT> token that
follows <TT>noexcept</TT>...

</BLOCKQUOTE>

</OL>

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