Skip to content

Commit a27e5a6

Browse files
[stmt.label, except.pre] Use new wording "control-flow-limited" statement (cplusplus#5413)
A new term of art (control-flow-limited statement) is introduced in [stmt.label] to express the restrictions on control flow into a statement (namely jumping to labels). Both [stmt.if] and [except.pre] are updated to use the new term. This rewords "shall not be used to" avoiding question of actual "use": the "shall not be used to" phrasing may be taken to refer only in cases where the actual use occurs or is the primary intent. Instead, the intended restriction can be written in terms of static properties of the constructs so restricted in the style of [stmt.if].
1 parent 2940703 commit a27e5a6

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

‎source/exceptions.tex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
\indextext{\idxcode{switch}!and try block}%
7373
\indextext{\idxcode{goto}!and handler}%
7474
\indextext{\idxcode{switch}!and handler}%
75-
A \tcode{goto} or \keyword{switch} statement shall not be used to transfer control
76-
into a try block or into a handler.
75+
The \grammarterm{compound-statement} of a try block or of a handler is a
76+
control-flow-limited statement\iref{stmt.label}.
7777
\begin{example}
7878
\begin{codeblock}
7979
void f() {

‎source/statements.tex‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@
152152
\indextext{label!\idxcode{default}}%
153153
Case labels and default labels shall occur only in \keyword{switch} statements.
154154

155+
\pnum
156+
A \defnadj{control-flow-limited}{statement} is a statement \tcode{S} for which:
157+
\begin{itemize}
158+
\item
159+
a \keyword{case} or \keyword{default} label appearing within \tcode{S} shall
160+
be associated with a \keyword{switch} statement\iref{stmt.switch} within
161+
\tcode{S}, and
162+
\item
163+
a label declared in \tcode{S} shall only be referred to by a
164+
statement\iref{stmt.goto} in \tcode{S}.
165+
\end{itemize}
166+
155167

156168
\rSec1[stmt.expr]{Expression statement}%
157169
\indextext{statement!expression}
@@ -277,6 +289,8 @@
277289
enclosing templated entity\iref{temp.pre}, if the condition is
278290
not value-dependent after its instantiation, the discarded substatement
279291
(if any) is not instantiated.
292+
Each substatement of a constexpr if statement is a control-flow-limited
293+
statement\iref{stmt.label}.
280294
\begin{example}
281295
\begin{codeblock}
282296
if constexpr (sizeof(int[2])) {} // OK, narrowing allowed
@@ -286,12 +300,6 @@
286300
Odr-uses\iref{term.odr.use} in a discarded statement do not require
287301
an entity to be defined.
288302
\end{note}
289-
A \keyword{case} or \keyword{default} label appearing within such an
290-
\keyword{if} statement shall be associated with a \keyword{switch}
291-
statement\iref{stmt.switch} within the same \keyword{if} statement.
292-
A label\iref{stmt.label} declared in a substatement of a constexpr if
293-
statement shall only be referred to by a statement\iref{stmt.goto} in
294-
the same substatement.
295303
\begin{example}
296304
\begin{codeblock}
297305
template<typename T, typename ... Rest> void g(T&& p, Rest&& ...rs) {
@@ -364,12 +372,8 @@
364372
\end{note}
365373
Otherwise, if the \keyword{else} part of the selection statement is present,
366374
then the second substatement is executed.
367-
A \keyword{case} or \keyword{default} label
368-
appearing within such an \keyword{if} statement
369-
shall be associated with a \keyword{switch} statement
370-
within the same \keyword{if} statement.
371-
A label declared in a substatement of a consteval if statement
372-
shall only be referred to by a statement in the same substatement.
375+
Each substatement of a consteval if statement is a control-flow-limited
376+
statement\iref{stmt.label}.
373377

374378
\pnum
375379
An \keyword{if} statement of the form

0 commit comments

Comments
 (0)