13 KiB
[stmt.pre]
8 Statements [stmt]
8.1 Preamble [stmt.pre]
Except as indicated, statements are executed in sequence ([intro.execution]).
statement:
labeled-statement
attribute-specifier-seqopt expression-statement
attribute-specifier-seqopt compound-statement
attribute-specifier-seqopt selection-statement
attribute-specifier-seqopt iteration-statement
attribute-specifier-seqopt expansion-statement
attribute-specifier-seqopt jump-statement
attribute-specifier-seqopt assertion-statement
declaration-statement
attribute-specifier-seqopt try-block
init-statement:
expression-statement
simple-declaration
alias-declaration
condition:
expression
attribute-specifier-seqopt decl-specifier-seq declarator brace-or-equal-initializer
structured-binding-declaration initializer
for-range-declaration:
attribute-specifier-seqopt decl-specifier-seq declarator
structured-binding-declaration
for-range-initializer:
expr-or-braced-init-list
The optional attribute-specifier-seq appertains to the respective statement.
See [dcl.meaning] for the optional attribute-specifier-seq in afor-range-declaration.
A substatement of a statement is one of the following:
for a labeled-statement, its statement,
for a compound-statement, any statement of its statement-seq,
for a selection-statement, any of its statements or compound-statements (but not its init-statement),
for an iteration-statement, its statement (but not an init-statement), or
for an expansion-statement, its compound-statement (but not an init-statement).
[Note 1:
The compound-statement of a lambda-expression is not a substatement of the statement (if any) in which the lambda-expression lexically appears.
â end note]
A statement S1 encloses a statement S2 if
S2 is a substatement of S1,
S1 is a selection-statement, iteration-statement, or expansion-statement, and S2 is the init-statement of S1,
S1 is a try-block and S2 is its compound-statement or any of the compound-statements of its handlers, or
S1 encloses a statement S3 and S3 encloses S2.
A statement S1 isenclosed by a statement S2 ifS2 encloses S1.
The rules for conditions apply both to selection-statements ([stmt.select]) and to the for and while statements ([stmt.iter]).
If a structured-binding-declaration appears in a condition, the condition is a structured binding declaration ([dcl.pre]).
A condition that is neither an expression nor a structured binding declaration is a declaration ([dcl]).
The declarator shall not specify a function or an array.
The decl-specifier-seq shall not define a class or enumeration.
If the auto type-specifier appears in the decl-specifier-seq, the type of the identifier being declared is deduced from the initializer as described in [dcl.spec.auto].
The decision variable of a condition that is neither an expression nor a structured binding declaration is the declared variable.
The decision variable of a condition that is a structured binding declaration is specified in [dcl.struct.bind].
The value of a condition that is not an expression in a statement other than a switch statement is the value of the decision variable contextually converted to bool ([conv]).
If that conversion is ill-formed, the program is ill-formed.
The value of acondition that is an expression is the value of the expression, contextually converted to bool for statements other than switch; if that conversion is ill-formed, the program is ill-formed.
The value of the condition will be referred to as simply âthe conditionâ where the usage is unambiguous.
If a condition can be syntactically resolved as either an expression or a declaration, it is interpreted as the latter.
In the decl-specifier-seq of a condition or of a for-range-declaration, including that of any structured-binding-declaration of the condition, eachdecl-specifier shall be either a type-specifier or constexpr.
The decl-specifier-seq of a for-range-declaration shall not define a class or enumeration.