Skip to content

Commit 104f2dd

Browse files
authored
Merge 2022-07 CWG Motion 7
P2324R2 Labels at the end of compound statements (C compatibility)
2 parents b8cdacb + aab09dc commit 104f2dd

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

source/statements.tex

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,25 @@
117117
\grammarterm{decl-specifier} shall be either a \grammarterm{type-specifier}
118118
or \keyword{constexpr}.
119119

120-
\rSec1[stmt.label]{Labeled statement}%
120+
\rSec1[stmt.label]{Label}%
121121
\indextext{statement!labeled}
122122

123123
\pnum
124124
\indextext{statement!labeled}%
125125
\indextext{\idxcode{:}!label specifier}%
126-
A statement can be labeled.
126+
A label can be added to a statement or
127+
used anywhere in a \grammarterm{compound-statement}.
128+
129+
\begin{bnf}
130+
\nontermdef{label}\br
131+
\opt{attribute-specifier-seq} identifier \terminal{:}\br
132+
\opt{attribute-specifier-seq} \keyword{case} constant-expression \terminal{:}\br
133+
\opt{attribute-specifier-seq} \keyword{default} \terminal{:}
134+
\end{bnf}
127135

128136
\begin{bnf}
129137
\nontermdef{labeled-statement}\br
130-
\opt{attribute-specifier-seq} identifier \terminal{:} statement\br
131-
\opt{attribute-specifier-seq} \keyword{case} constant-expression \terminal{:} statement\br
132-
\opt{attribute-specifier-seq} \keyword{default} \terminal{:} statement
138+
label statement
133139
\end{bnf}
134140

135141
The optional \grammarterm{attribute-specifier-seq} appertains to the label.
@@ -139,7 +145,7 @@
139145
\indextext{label!scope of}%
140146
No two labels in a function shall have the same \grammarterm{identifier}.
141147
A label can be used in a \tcode{goto} statement
142-
before its introduction by a \grammarterm{labeled-statement}.
148+
before its introduction.
143149

144150
\pnum
145151
\indextext{label!\idxcode{case}}%
@@ -169,8 +175,7 @@
169175
a \defn{null statement}.
170176
\begin{note}
171177
Most statements are expression statements --- usually assignments or
172-
function calls. A null statement is useful to carry a label just before
173-
the \tcode{\}} of a compound statement and to supply a null body to an
178+
function calls. A null statement is useful to supply a null body to an
174179
iteration statement such as a \keyword{while}
175180
statement\iref{stmt.while}.
176181
\end{note}
@@ -184,7 +189,7 @@
184189

185190
\begin{bnf}
186191
\nontermdef{compound-statement}\br
187-
\terminal{\{} \opt{statement-seq} \terminal{\}}
192+
\terminal{\{} \opt{statement-seq} \opt{label-seq} \terminal{\}}
188193
\end{bnf}
189194

190195
\begin{bnf}
@@ -193,6 +198,16 @@
193198
statement-seq statement
194199
\end{bnf}
195200

201+
\begin{bnf}
202+
\nontermdef{label-seq}\br
203+
label\br
204+
label-seq label
205+
\end{bnf}
206+
207+
A label at the end of a \grammarterm{compound-statement}
208+
is treated as if it were followed by a null statement.
209+
210+
\pnum
196211
\begin{note}
197212
A compound statement defines a block scope\iref{basic.scope}.
198213
A declaration is a \grammarterm{statement}\iref{stmt.dcl}.

0 commit comments

Comments
 (0)