61 lines
3.1 KiB
Markdown
61 lines
3.1 KiB
Markdown
[stmt.label]
|
||
|
||
# 8 Statements [[stmt]](./#stmt)
|
||
|
||
## 8.2 Label [stmt.label]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L163)
|
||
|
||
A label can be added to a statement or
|
||
used anywhere in a [*compound-statement*](stmt.block#nt:compound-statement "8.4 Compound statement or block [stmt.block]")[.](#1.sentence-1)
|
||
|
||
[label:](#nt:label "8.2 Label [stmt.label]")
|
||
[*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") :
|
||
[*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt case [*constant-expression*](expr.const#nt:constant-expression "7.7 Constant expressions [expr.const]") :
|
||
[*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt default :
|
||
|
||
[labeled-statement:](#nt:labeled-statement "8.2 Label [stmt.label]")
|
||
[*label*](#nt:label "8.2 Label [stmt.label]") [*statement*](stmt.pre#nt:statement "8.1 Preamble [stmt.pre]")
|
||
|
||
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") appertains to the label[.](#1.sentence-2)
|
||
|
||
The only use of a label with an [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") is
|
||
as the target of a goto[.](#1.sentence-3)
|
||
|
||
No two labels in a function shall have the same [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")[.](#1.sentence-4)
|
||
|
||
A label can be used in a goto statement
|
||
before its introduction[.](#1.sentence-5)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L190)
|
||
|
||
A [*labeled-statement*](#nt:labeled-statement "8.2 Label [stmt.label]") whose [*label*](#nt:label "8.2 Label [stmt.label]") is a case or default label
|
||
shall be enclosed by ([[stmt.pre]](stmt.pre "8.1 Preamble")) a switch statement ([[stmt.switch]](stmt.switch "8.5.3 The switch statement"))[.](#2.sentence-1)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L198)
|
||
|
||
A [*control-flow-limited statement*](#def:statement,control-flow-limited "8.2 Label [stmt.label]") is a statement S for which:
|
||
|
||
- [(3.1)](#3.1)
|
||
|
||
a case or default label appearing within S shall
|
||
be associated with a switch statement ([[stmt.switch]](stmt.switch "8.5.3 The switch statement")) within S, and
|
||
|
||
- [(3.2)](#3.2)
|
||
|
||
a label declared in S shall only be referred to by a
|
||
statement ([[stmt.goto]](stmt.goto "8.8.6 The goto statement")) in S[.](#3.sentence-1)
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/statements.tex#L210)
|
||
|
||
An identifier label shall not be enclosed
|
||
by an [*expansion-statement*](stmt.expand#nt:expansion-statement "8.7 Expansion statements [stmt.expand]") ([[stmt.expand]](stmt.expand "8.7 Expansion statements"))[.](#4.sentence-1)
|