<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2616</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="2616"></A><H4>2616.
  
Imprecise restrictions on <TT>break</TT> and <TT>continue</TT>
</H4>
<B>Section: </B>Clause 8&#160; [<A href="https://wg21.link/stmt">stmt</A>]
 &#160;&#160;&#160;

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

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

 <B>Date: </B>2022-08-24<BR>


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

<P>Consider:</P>

<PRE>
for (int i = 0; i&lt; 10; ++i){
  auto f = [](){
    break; //<SPAN CLASS="cmnt"> #1</SPAN>
  };
}
</PRE>

<P>Subclause 8.8.2 [<A href="https://wg21.link/stmt.break#1">stmt.break</A>] paragraph 1 specifies:</P>

<BLOCKQUOTE>

The <TT>break</TT> statement shall occur only in
an <I>iteration-statement</I> or a <TT>switch</TT> statement and
causes termination of the smallest
enclosing <I>iteration-statement</I> or <TT>switch</TT> statement;
control passes to the statement following the terminated statement, if
any.

</BLOCKQUOTE>

<P>Does the <TT>break</TT> at #1 "occur" in the <TT>for</TT> loop?</P>

<P><B>Proposed resolution (approved by CWG 2022-08-26):</B></P>

<OL>

<LI>
<P>Append to 8.1 [<A href="https://wg21.link/stmt.pre#3">stmt.pre</A>] paragraph 3 as follows:</P>

<BLOCKQUOTE>
<P>... <INS>A statement S1 is <I>enclosed by</I> a statement S2 if S2
encloses S1.</INS>
</P>

<P>The rules for conditions apply both...</P>
</BLOCKQUOTE>

</LI>

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

<BLOCKQUOTE>

<DEL>Case labels and default labels shall occur only
in <TT>switch</TT> statements</DEL>
<INS>A <I>labeled-statement</I> whose <I>label</I> is a case or
default label shall be enclosed by (8.1 [<A href="https://wg21.link/stmt.pre">stmt.pre</A>])
a <TT>switch</TT> statement (8.5.3 [<A href="https://wg21.link/stmt.switch">stmt.switch</A>]).</INS>.

</BLOCKQUOTE>

</LI>

<LI>

<P>Change in 8.8.2 [<A href="https://wg21.link/stmt.break#1">stmt.break</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

<DEL>The</DEL> <INS>A</INS> <TT>break</TT> statement shall <DEL>occur
only in</DEL> <INS>be enclosed by (8.1 [<A href="https://wg21.link/stmt.pre">stmt.pre</A>])</INS>
an <I>iteration-statement</I> <INS>(8.6 [<A href="https://wg21.link/stmt.iter">stmt.iter</A>])</INS> or
a <TT>switch</TT>
statement <DEL>and</DEL> <INS>(8.5.3 [<A href="https://wg21.link/stmt.switch">stmt.switch</A>]). The <TT>break</TT>
statement</INS> causes termination of the smallest
<INS>such</INS> enclosing
<DEL><I>iteration-statement</I> or <TT>switch</TT></DEL> statement;
control passes to the statement following the terminated statement, if
any.

</BLOCKQUOTE>

</LI>

<LI>

<P>Change in 8.8.3 [<A href="https://wg21.link/stmt.cont#1">stmt.cont</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

<DEL>The</DEL> <INS>A</INS> <TT>continue</TT> statement
shall <DEL>occur only in</DEL> <INS>be enclosed by
(8.1 [<A href="https://wg21.link/stmt.pre">stmt.pre</A>])</INS> an <I>iteration-statement</I>
<INS>(8.6 [<A href="https://wg21.link/stmt.iter">stmt.iter</A>])</INS>
<DEL>and</DEL><INS>. The <TT>continue</TT> statement</INS> causes
control to pass to the loop-continuation portion of the smallest
<INS>such</INS> enclosing
<DEL><I>iteration-statement</I></DEL> <INS>statement</INS>,
that is, to the end of the loop. ...

</BLOCKQUOTE>

</LI>

</OL>

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