<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2763</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="2763"></A><H4>2763.
  
Ignorability of [[noreturn]] during constant evaluation
</H4>
<B>Section: </B>7.7&#160; [<A href="https://wg21.link/expr.const">expr.const</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Jiang An
 &#160;&#160;&#160;

 <B>Date: </B>2023-07-10<BR>


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

<P>Subclause 9.13.10 [<A href="https://wg21.link/dcl.attr.noreturn#2">dcl.attr.noreturn</A>] paragraph 2 specifies:</P>

<BLOCKQUOTE>

If a function f is called where f was previously declared with the
<TT>noreturn</TT> attribute and f eventually returns, the behavior is
undefined.

</BLOCKQUOTE>

<P>Undefineed behavior is, in general, detected during constant
evaluation, thus requiring an implementation to actually support
the <TT>noreturn</TT> attribute, such as in the following example:</P>

<PRE>
  [[noreturn]] constexpr void f() {}
  constexpr int x = (f(), 0);
</PRE>

<P>It might be desirable to treat the <TT>assume</TT>
and <TT>noreturn</TT> attributes alike in that regard.</P>

<P><B>Proposed resolution (approved by CWG 2023-07-14) [SUPERSEDED]:</B></P>

<P>Split into a separate paragraph and change 7.7 [<A href="https://wg21.link/expr.const#5">expr.const</A>] paragraph 5 as follows:</P>

<BLOCKQUOTE>

It is unspecified whether E is a core constant expression if E
satisfies the constraints of a core constant expression, but
evaluation of E would evaluate
<UL>
<LI>an operation that has undefined
behavior as specified in Clause 16 through Clause 33,</LI>
<LI>an invocation of the va_start macro
(17.14.2 [<A href="https://wg21.link/cstdarg.syn">cstdarg.syn</A>]), <DEL>or</DEL>
</LI>
<LI class="ins">a <TT>return</TT> statement in a function that was
previously declared with the <TT>noreturn</TT> attribute
(9.13.10 [<A href="https://wg21.link/dcl.attr.noreturn">dcl.attr.noreturn</A>]), or</LI>
<LI>
a statement with an assumption (9.13.3 [<A href="https://wg21.link/dcl.attr.assume">dcl.attr.assume</A>])
whose converted <I>conditional-expression</I>, if evaluated where the
assumption appears, would not disqualify E from being a core constant
expression and would not evaluate to <TT>true</TT>.  [ Note: .... ]</LI>
</UL>

</BLOCKQUOTE>

<P><B>CWG 2023-07-14</B></P>

<P>As an alternative, all of 9.13 [<A href="https://wg21.link/dcl.attr">dcl.attr</A>] could be added
to the "library undefined behavior" bullet.  However, CWG felt that a
case-by-case consideration is warranted, given that assumptions set
precedent in requiring special treatment.</P>

<P><B>Possible resolution (reviewed by CWG 2023-08-25) [SUPERSEDED]:</B></P>

<P>Split into a separate paragraph and change 7.7 [<A href="https://wg21.link/expr.const#5">expr.const</A>] paragraph 5 as follows:</P>

<BLOCKQUOTE>

<UL>
<LI>...</LI>
<LI>
an operation that would have undefined behavior as specified in
Clause 4 [<A href="https://wg21.link/intro">intro</A>] through Clause 15 [<A href="https://wg21.link/cpp">cpp</A>], excluding
9.13.3 [<A href="https://wg21.link/dcl.attr.assume">dcl.attr.assume</A>] <INS>and 9.13.10 [<A href="https://wg21.link/dcl.attr.noreturn">dcl.attr.noreturn</A>]</INS>; [
Footnote: ...]
</LI>
<LI>...</LI>
</UL>

It is unspecified whether E is a core constant expression if E
satisfies the constraints of a core constant expression, but
evaluation of E would evaluate
<UL>
<LI>an operation that has undefined
behavior as specified in Clause 16 through Clause 33,</LI>
<LI>an invocation of the va_start macro
(17.14.2 [<A href="https://wg21.link/cstdarg.syn">cstdarg.syn</A>]), <DEL>or</DEL>
</LI>
<LI class="ins">a <TT>return</TT> statement in a function that was
previously declared with the <TT>noreturn</TT> attribute
(9.13.10 [<A href="https://wg21.link/dcl.attr.noreturn">dcl.attr.noreturn</A>]), or</LI>
<LI>
a statement with an assumption (9.13.3 [<A href="https://wg21.link/dcl.attr.assume">dcl.attr.assume</A>])
whose converted <I>conditional-expression</I>, if evaluated where the
assumption appears, would not disqualify E from being a core constant
expression and would not evaluate to <TT>true</TT>.  [ Note: .... ]</LI>
</UL>

</BLOCKQUOTE>

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

<P>Split into a separate paragraph and change 7.7 [<A href="https://wg21.link/expr.const#5">expr.const</A>] paragraph 5 as follows:</P>

<BLOCKQUOTE>

<UL>
<LI>...</LI>
<LI>
an operation that would have undefined behavior as specified in
Clause 4 [<A href="https://wg21.link/intro">intro</A>] through Clause 15 [<A href="https://wg21.link/cpp">cpp</A>], excluding
9.13.3 [<A href="https://wg21.link/dcl.attr.assume">dcl.attr.assume</A>] <INS>and 9.13.10 [<A href="https://wg21.link/dcl.attr.noreturn">dcl.attr.noreturn</A>]</INS>; [
Footnote: ...]
</LI>
<LI>...</LI>
</UL>

It is unspecified whether E is a core constant expression if E
satisfies the constraints of a core constant expression, but
evaluation of E would evaluate
<UL>
<LI>an operation that has undefined
behavior as specified in Clause 16 through Clause 33,</LI>
<LI>an invocation of the va_start macro
(17.14.2 [<A href="https://wg21.link/cstdarg.syn">cstdarg.syn</A>]), <DEL>or</DEL>
</LI>
<LI class="ins">a call to a function that was previously declared
with the <TT>noreturn</TT> attribute (9.13.10 [<A href="https://wg21.link/dcl.attr.noreturn">dcl.attr.noreturn</A>])
and that call returns to its caller, or</LI>
<LI>
a statement with an assumption (9.13.3 [<A href="https://wg21.link/dcl.attr.assume">dcl.attr.assume</A>])
whose converted <I>conditional-expression</I>, if evaluated where the
assumption appears, would not disqualify E from being a core constant
expression and would not evaluate to <TT>true</TT>.  [ Note: .... ]</LI>
</UL>

</BLOCKQUOTE>

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