From efdae1a6b8187440384eda244a32ec5855687e1c Mon Sep 17 00:00:00 2001 From: Eisenwave Date: Sun, 22 Nov 2026 11:07:17 -0300 Subject: [PATCH 1/3] P3568R4 break label; and continue label; --- source/basic.tex | 3 +- source/preprocessor.tex | 1 + source/statements.tex | 104 +++++++++++++++++++++++++++++----------- 3 files changed, 79 insertions(+), 29 deletions(-) diff --git a/source/basic.tex b/source/basic.tex index 2f9a6abdc8..8138004fe2 100644 --- a/source/basic.tex +++ b/source/basic.tex @@ -37,7 +37,8 @@ \grammarterm{label}\iref{stmt.label} or \grammarterm{literal-operator-id}\iref{over.literal}, \item - the \grammarterm{identifier} following a \keyword{goto} in a + the \grammarterm{identifier} (if any) + following a \keyword{goto}, \keyword{break}, or \keyword{continue} in a \grammarterm{jump-statement}\iref{stmt.jump.general}, \item any \grammarterm{identifier} in a diff --git a/source/preprocessor.tex b/source/preprocessor.tex index 7ddec0a17e..283b5ce2cc 100644 --- a/source/preprocessor.tex +++ b/source/preprocessor.tex @@ -2410,6 +2410,7 @@ \defnxname{cpp_attributes} & \tcode{200809L} \\ \rowsep \defnxname{cpp_auto_cast} & \tcode{202110L} \\ \rowsep \defnxname{cpp_binary_literals} & \tcode{201304L} \\ \rowsep +\defnxname{cpp_break_label} & \tcode{202611L} \\ \rowsep \defnxname{cpp_capture_star_this} & \tcode{201603L} \\ \rowsep \defnxname{cpp_char8_t} & \tcode{202207L} \\ \rowsep \defnxname{cpp_concepts} & \tcode{202606L} \\ \rowsep diff --git a/source/statements.tex b/source/statements.tex index 846b203c04..bd89aaa628 100644 --- a/source/statements.tex +++ b/source/statements.tex @@ -181,13 +181,31 @@ \end{bnf} The optional \grammarterm{attribute-specifier-seq} appertains to the label. +\begin{note} \indextext{statement!\idxcode{goto}}% -The only use of a label with an \grammarterm{identifier} is -as the target of a \tcode{goto}. -\indextext{label!scope of}% -No two labels in a function shall have the same \grammarterm{identifier}. A label can be used in a \tcode{goto} statement before its introduction. +\indextext{label!scope of}% +A function can contain multiple labels with the same identifier, +but such duplicate labels cannot be used in a \tcode{goto} statement. +\end{note} + +\pnum +An \grammarterm{identifier} $J$ +\defnx{labels}{label!\idxgram{statement}} a \grammarterm{statement} $S$ if +$S$ is the \grammarterm{statement} of a \grammarterm{labeled-statement} $X$ and +\begin{itemize} +\item $J$ is the \grammarterm{identifier} (if any) of the \grammarterm{label} of $X$, or +\item $J$ labels $X$. +\end{itemize} +\begin{example} +\begin{codeblock} +a: b: while (0) { } // both \tcode{a} and \tcode{b} label the loop +c: { d: switch (0) { // unlike \tcode{c}, \tcode{d} labels the \tcode{switch} statement + e: default: f: while (0) { } // both \tcode{e} and \tcode{f} label the loop +} } +\end{codeblock} +\end{example} \pnum \indextext{\idxgram{labeled-statement}}% @@ -206,13 +224,9 @@ \tcode{S}, and \item a label declared in \tcode{S} shall only be referred to by a - statement\iref{stmt.goto} in \tcode{S}. + statement in \tcode{S}. \end{itemize} -\pnum -An identifier label shall not be enclosed -by an \grammarterm{expansion-statement}\iref{stmt.expand}. - \rSec1[stmt.expr]{Expression statement}% \indextext{statement!expression} @@ -1017,11 +1031,11 @@ % \begin{bnf} \nontermdef{jump-statement}\br - \keyword{break} \terminal{;}\br - \keyword{continue} \terminal{;}\br + \keyword{goto} identifier \terminal{;}\br + \keyword{break} \opt{identifier} \terminal{;}\br + \keyword{continue} \opt{identifier} \terminal{;}\br \keyword{return} \opt{expr-or-braced-init-list} \terminal{;}\br - coroutine-return-statement\br - \keyword{goto} identifier \terminal{;} + coroutine-return-statement \end{bnf} \pnum @@ -1049,27 +1063,59 @@ \indextext{statement!\idxcode{break}} \pnum -A \keyword{break} statement shall be enclosed by\iref{stmt.pre} +A \defnadj{breakable}{statement} is \indextext{\idxgram{iteration-statement}}% -\indextext{statement!\idxcode{switch}}% an \grammarterm{iteration-statement}\iref{stmt.iter}, +\indextext{\idxgram{expansion-statement}}% an \grammarterm{expansion-statement}\iref{stmt.expand}, or +\indextext{statement!\idxcode{switch}}% a \keyword{switch} statement\iref{stmt.switch}. -The \keyword{break} statement causes -termination of the innermost such enclosing statement; -control passes to the statement following the -terminated statement, if any. +The \keyword{break} statement +selects an enclosing \grammarterm{statement} $S$ as follows: +\begin{itemize} +\item +If an identifier $J$ is present, +$S$ is the innermost enclosing statement labeled by $J$. +\item +Otherwise, $S$ is the innermost enclosing breakable statement. +\end{itemize} +$S$ shall exist and shall be a breakable statement. +Control passes to the statement following $S$, if any. +\begin{example} +\begin{codeblock} +y: a: b: while (/* ... */) { + a: a: c: for (/* ... */) { + break; // OK, terminates enclosing \tcode{for} loop + break a; // OK, same + break b; // OK, terminates enclosing \tcode{while} loop + y: { break y; } // error: \tcode{break} does not refer to a breakable statement + } + break c; // error: \tcode{break} does not refer to an enclosing statement +} +break; // error: \tcode{break} is not enclosed by a breakable statement +\end{codeblock} +\end{example} \rSec2[stmt.cont]{The \keyword{continue} statement}% \indextext{statement!\idxcode{continue}} \pnum -A \keyword{continue} -statement shall be enclosed by\iref{stmt.pre} +A \defnadj{continuable}{statement} is \indextext{\idxgram{iteration-statement}}% -an \grammarterm{iteration-statement} or an \grammarterm{expansion-statement}. -If the innermost enclosing such statement $X$ -is an \grammarterm{iteration-statement}\iref{stmt.iter}, +an \grammarterm{iteration-statement}\iref{stmt.iter} or +\indextext{\idxgram{expansion-statement}}% +an \grammarterm{expansion-statement}\iref{stmt.expand}. +The \tcode{continue} statement +selects and enclosing statement $X$ as follows: +\begin{itemize} +\item +If an \grammarterm{identifier} $J$ is present, +$X$ is the innermost enclosing statement labeled by $J$. +\item +Otherwise, $X$ is the innermost enclosing continuable statement. +\end{itemize} +$X$ shall exist and shall be a continuable statement. +If $X$ is an \grammarterm{iteration-statement}\iref{stmt.iter}, the \keyword{continue} statement causes control to pass to the end of the \grammarterm{statement} of $X$. Otherwise, control passes to the end of the \grammarterm{compound-statement} @@ -1231,10 +1277,12 @@ \indextext{statement!\idxcode{goto}} \pnum -The \tcode{goto} statement unconditionally transfers control to the -statement labeled by the identifier. The identifier shall be a -\indextext{label}% -label\iref{stmt.label} located in the current function. +A \tcode{goto} statement with an \grammarterm{identifier} $J$ +unconditionally transfers control to a \grammarterm{labeled-statement} +where the identifier of the \grammarterm{label} is $J$, +in the current function. +There shall be exactly one such statement, +and such a statement shall not be enclosed by an \grammarterm{expansion-statement}. \rSec1[stmt.contract.assert]{Assertion statement} From 1a2e2cc5f6f49ab20de0ce4cdef3c093ae46ccfa Mon Sep 17 00:00:00 2001 From: Eisenwave Date: Sun, 22 Nov 2026 12:33:11 -0300 Subject: [PATCH 2/3] Fixup: Resolve Jens review comments --- source/statements.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/statements.tex b/source/statements.tex index bd89aaa628..fe26d951ec 100644 --- a/source/statements.tex +++ b/source/statements.tex @@ -183,10 +183,10 @@ The optional \grammarterm{attribute-specifier-seq} appertains to the label. \begin{note} \indextext{statement!\idxcode{goto}}% -A label can be used in a \tcode{goto} statement +A label can be used in a \tcode{goto} statement\iref{stmt.goto} before its introduction. \indextext{label!scope of}% -A function can contain multiple labels with the same identifier, +A function can contain multiple labels with the same \grammarterm{identifier}, but such duplicate labels cannot be used in a \tcode{goto} statement. \end{note} From 665c4ea3658332c4cff322fdcf15907e6d0ce6e2 Mon Sep 17 00:00:00 2001 From: Eisenwave Date: Mon, 30 Nov 2026 09:18:07 +0100 Subject: [PATCH 3/3] Fixup: Resolve various review comments --- source/statements.tex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/statements.tex b/source/statements.tex index fe26d951ec..152a502b7b 100644 --- a/source/statements.tex +++ b/source/statements.tex @@ -1105,8 +1105,8 @@ an \grammarterm{iteration-statement}\iref{stmt.iter} or \indextext{\idxgram{expansion-statement}}% an \grammarterm{expansion-statement}\iref{stmt.expand}. -The \tcode{continue} statement -selects and enclosing statement $X$ as follows: +The \keyword{continue} statement +selects an enclosing statement $X$ as follows: \begin{itemize} \item If an \grammarterm{identifier} $J$ is present, @@ -1279,7 +1279,8 @@ \pnum A \tcode{goto} statement with an \grammarterm{identifier} $J$ unconditionally transfers control to a \grammarterm{labeled-statement} -where the identifier of the \grammarterm{label} is $J$, +\indextext{label}% +where the \grammarterm{identifier} of the \grammarterm{label} is $J$, in the current function. There shall be exactly one such statement, and such a statement shall not be enclosed by an \grammarterm{expansion-statement}.