|
117 | 117 | \grammarterm{decl-specifier} shall be either a \grammarterm{type-specifier}
|
118 | 118 | or \keyword{constexpr}.
|
119 | 119 |
|
120 |
| -\rSec1[stmt.label]{Labeled statement}% |
| 120 | +\rSec1[stmt.label]{Label}% |
121 | 121 | \indextext{statement!labeled}
|
122 | 122 |
|
123 | 123 | \pnum
|
124 | 124 | \indextext{statement!labeled}%
|
125 | 125 | \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} |
127 | 135 |
|
128 | 136 | \begin{bnf}
|
129 | 137 | \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 |
133 | 139 | \end{bnf}
|
134 | 140 |
|
135 | 141 | The optional \grammarterm{attribute-specifier-seq} appertains to the label.
|
|
139 | 145 | \indextext{label!scope of}%
|
140 | 146 | No two labels in a function shall have the same \grammarterm{identifier}.
|
141 | 147 | A label can be used in a \tcode{goto} statement
|
142 |
| -before its introduction by a \grammarterm{labeled-statement}. |
| 148 | +before its introduction. |
143 | 149 |
|
144 | 150 | \pnum
|
145 | 151 | \indextext{label!\idxcode{case}}%
|
|
169 | 175 | a \defn{null statement}.
|
170 | 176 | \begin{note}
|
171 | 177 | 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 |
174 | 179 | iteration statement such as a \keyword{while}
|
175 | 180 | statement\iref{stmt.while}.
|
176 | 181 | \end{note}
|
|
184 | 189 |
|
185 | 190 | \begin{bnf}
|
186 | 191 | \nontermdef{compound-statement}\br
|
187 |
| - \terminal{\{} \opt{statement-seq} \terminal{\}} |
| 192 | + \terminal{\{} \opt{statement-seq} \opt{label-seq} \terminal{\}} |
188 | 193 | \end{bnf}
|
189 | 194 |
|
190 | 195 | \begin{bnf}
|
|
193 | 198 | statement-seq statement
|
194 | 199 | \end{bnf}
|
195 | 200 |
|
| 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 |
196 | 211 | \begin{note}
|
197 | 212 | A compound statement defines a block scope\iref{basic.scope}.
|
198 | 213 | A declaration is a \grammarterm{statement}\iref{stmt.dcl}.
|
|
0 commit comments