<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2710</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="2710"></A><H4>2710.
  
Loops in constant expressions
</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>Daniel Kr&#252;gler
 &#160;&#160;&#160;

 <B>Date: </B>2023-03-23<BR>


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



<P>Iteration statements such as <TT>while</TT> and <TT>for</TT> loops
are specified by equivalent code involving <TT>goto</TT>
(8.6.2 [<A href="https://wg21.link/stmt.while#2">stmt.while</A>] paragraph 2, 8.6.4 [<A href="https://wg21.link/stmt.for#1">stmt.for</A>] paragraph 1, 8.6.5 [<A href="https://wg21.link/stmt.ranged#1">stmt.ranged</A>] paragraph 1).  The <TT>goto</TT>
statement cannot be evaluated in constant expressions
(7.7 [<A href="https://wg21.link/expr.const#5.30">expr.const</A>] bullet 5.30), thus <TT>while</TT>
and <TT>for</TT> loops cannot be evaluated in constant expressions.
Similar concerns arise for <TT>continue</TT>
(8.8.3 [<A href="https://wg21.link/stmt.cont#1">stmt.cont</A>] paragraph 1).</P>

<P>However, that is neither intended nor existing practice.</P>

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

<P>Change in 7.7 [<A href="https://wg21.link/expr.const#5.30">expr.const</A>] bullet 5.30 as follows:</P>

<BLOCKQUOTE>
An expression E is a <I>core constant expression</I> unless the
evaluation of E, following the rules of the abstract machine
(6.10.1 [<A href="https://wg21.link/intro.execution">intro.execution</A>]), would evaluate one of the following:
<UL>
<LI>...</LI>
<LI>a goto statement (8.8.6 [<A href="https://wg21.link/stmt.goto">stmt.goto</A>])
<INS>unless it is introduced by replacing
an <I>iteration-statement</I> (8.6 [<A href="https://wg21.link/stmt.iter">stmt.iter</A>]) or
a <TT>continue</TT> statement (8.8.3 [<A href="https://wg21.link/stmt.cont">stmt.cont</A>]) with its
equivalent</INS>.
</LI>
</UL>

</BLOCKQUOTE>

<P><B>CWG 2023-03-30</B></P>

<P>Keep the rule non-normative and non-exhaustive.</P>

<P><B>Proposed resolution (approved by CWG 2023-04-28):</B></P>

<P>Change in 7.7 [<A href="https://wg21.link/expr.const#5.30">expr.const</A>] bullet 5.30 as follows:</P>

<BLOCKQUOTE>
An expression E is a <I>core constant expression</I> unless the
evaluation of E, following the rules of the abstract machine
(6.10.1 [<A href="https://wg21.link/intro.execution">intro.execution</A>]), would evaluate one of the following:
<UL>
<LI>...</LI>
<LI>a goto statement (8.8.6 [<A href="https://wg21.link/stmt.goto">stmt.goto</A>]).
<INS>[ Note: A <TT>goto</TT> statement introduced by equivalence
(Clause 8 [<A href="https://wg21.link/stmt">stmt</A>]) is not in scope.  For example,
a <TT>while</TT> statement (8.6.2 [<A href="https://wg21.link/stmt.while">stmt.while</A>]) can be
executed during constant evaluation. -- end note ]</INS>.
</LI>
</UL>

</BLOCKQUOTE>

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