Skip to content

Commit

Permalink
[stmt] Move grammar and description of 'condition' up
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoeppe authored and zygoloid committed Jul 1, 2016
1 parent 347be70 commit f40f23d
Showing 1 changed file with 66 additions and 68 deletions.
134 changes: 66 additions & 68 deletions source/statements.tex
Expand Up @@ -24,10 +24,76 @@
\nontermdef{init-statement}\br
expression-statement\br
simple-declaration

\nontermdef{condition}\br
expression\br
attribute-specifier-seq\opt decl-specifier-seq declarator \terminal{=} initializer-clause\br
attribute-specifier-seq\opt decl-specifier-seq declarator braced-init-list
\end{bnf}

The optional \grammarterm{attribute-specifier-seq} appertains to the respective statement.

\pnum
\indextext{\idxgram{condition}{s}!rules~for}%
The rules for \grammarterm{}{condition}{s} apply both to
\grammarterm{selection-statement}{s} and to the \tcode{for} and \tcode{while}
statements~(\ref{stmt.iter}). The \grammarterm{}{declarator} shall not
specify a function or an array. The \grammarterm{decl-specifier-seq} shall not
define a class or enumeration. If the \tcode{auto} \nonterminal{type-specifier} appears in
the \nonterminal{decl-specifier-seq},
the type of the identifier being declared is deduced from the initializer as described in~\ref{dcl.spec.auto}.

\pnum
\indextext{statement!declaration in \tcode{if}}%
\indextext{statement!declaration in \tcode{switch}}%
A name introduced by a declaration in a \grammarterm{}{condition} (either
introduced by the \grammarterm{decl-specifier-seq} or the
\grammarterm{}{declarator} of the condition) is in scope from its point of
declaration until the end of the substatements controlled by the
condition. If the name is re-declared in the outermost block of a
substatement controlled by the condition, the declaration that
re-declares the name is ill-formed.
\begin{example}

\begin{codeblock}
if (int x = f()) {
int x; // ill-formed, redeclaration of \tcode{x}
}
else {
int x; // ill-formed, redeclaration of \tcode{x}
}
\end{codeblock}
\end{example}

\pnum
The value of a \grammarterm{}{condition} that is an initialized declaration
in a statement other than a \tcode{switch} statement is the value of the
declared variable
contextually converted to \tcode{bool} (Clause~\ref{conv}).
If that
conversion is ill-formed, the program is ill-formed. The value of a
\grammarterm{}{condition} that is an initialized declaration in a
\tcode{switch} statement is the value of the declared variable if it has
integral or enumeration type, or of that variable implicitly converted
to integral or enumeration type otherwise. The value of a
\grammarterm{}{condition} that is an expression is the value of the
expression, contextually converted to \tcode{bool}
for statements other
than \tcode{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.

\pnum
If a \grammarterm{}{condition} can be syntactically resolved as either an
expression or the declaration of a block-scope name, it is interpreted as a
declaration.

\pnum
In the \grammarterm{decl-specifier-seq} of a \grammarterm{condition}, each
\grammarterm{decl-specifier} shall be either a \grammarterm{type-specifier}
or \tcode{constexpr}.

\rSec1[stmt.label]{Labeled statement}%
\indextext{statement!labeled}

Expand Down Expand Up @@ -137,13 +203,6 @@
\terminal{switch (} init-statement\opt condition \terminal{)} statement
\end{bnf}

\begin{bnf}
\nontermdef{condition}\br
expression\br
attribute-specifier-seq\opt decl-specifier-seq declarator \terminal{=} initializer-clause\br
attribute-specifier-seq\opt decl-specifier-seq declarator braced-init-list
\end{bnf}

See~\ref{dcl.meaning} for the optional \grammarterm{attribute-specifier-seq} in a condition.
\begin{note}
An \grammarterm{init-statement} ends with a semicolon.
Expand Down Expand Up @@ -176,67 +235,6 @@
Thus after the \tcode{if} statement, \tcode{i} is no longer in scope.
\end{example}

\pnum
\indextext{\idxgram{condition}{s}!rules~for}%
The rules for \grammarterm{}{condition}{s} apply both to
\grammarterm{selection-statement}{s} and to the \tcode{for} and \tcode{while}
statements~(\ref{stmt.iter}). The \grammarterm{}{declarator} shall not
specify a function or an array. The \grammarterm{decl-specifier-seq} shall not
define a class or enumeration. If the \tcode{auto} \nonterminal{type-specifier} appears in
the \nonterminal{decl-specifier-seq},
the type of the identifier being declared is deduced from the initializer as described in~\ref{dcl.spec.auto}.

\pnum
\indextext{statement!declaration in \tcode{if}}%
\indextext{statement!declaration in \tcode{switch}}%
A name introduced by a declaration in a \grammarterm{}{condition} (either
introduced by the \grammarterm{decl-specifier-seq} or the
\grammarterm{}{declarator} of the condition) is in scope from its point of
declaration until the end of the substatements controlled by the
condition. If the name is re-declared in the outermost block of a
substatement controlled by the condition, the declaration that
re-declares the name is ill-formed.
\begin{example}

\begin{codeblock}
if (int x = f()) {
int x; // ill-formed, redeclaration of \tcode{x}
}
else {
int x; // ill-formed, redeclaration of \tcode{x}
}
\end{codeblock}
\end{example}

\pnum
The value of a \grammarterm{}{condition} that is an initialized declaration
in a statement other than a \tcode{switch} statement is the value of the
declared variable
contextually converted to \tcode{bool} (Clause~\ref{conv}).
If that
conversion is ill-formed, the program is ill-formed. The value of a
\grammarterm{}{condition} that is an initialized declaration in a
\tcode{switch} statement is the value of the declared variable if it has
integral or enumeration type, or of that variable implicitly converted
to integral or enumeration type otherwise. The value of a
\grammarterm{}{condition} that is an expression is the value of the
expression, contextually converted to \tcode{bool}
for statements other
than \tcode{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.

\pnum
If a \grammarterm{}{condition} can be syntactically resolved as either an
expression or the declaration of a block-scope name, it is interpreted as a
declaration.

\pnum
In the \grammarterm{decl-specifier-seq} of a \grammarterm{condition}, each
\grammarterm{decl-specifier} shall be either a \grammarterm{type-specifier}
or \tcode{constexpr}.

\rSec2[stmt.if]{The \tcode{if} statement}%
\indextext{statement!\idxcode{if}}

Expand Down

0 comments on commit f40f23d

Please sign in to comment.