6
Basics
[basic]
6.4
Scope
[basic.scope]
6.4.3
Block scope
[basic.scope.block]
1
#
Each
(1.1)
selection or iteration statement (
[stmt.
select]
,
[stmt.
iter]
),
(1.2)
substatement of such a statement,
(1.3)
handler
(
[except.
pre]
), or
(1.4)
compound statement (
[stmt.
block]
) that is not the
compound-statement
of a
handler
introduces a
block scope
that includes that statement or
handler
.
[
Note
1
:
A substatement that is also a block has only one scope
.
—
end note
]
A variable that belongs to a block scope is a
block variable
.
[
Example
1
:
int
i
=
42
;
int
a
[
10
]
;
for
(
int
i
=
0
; i
<
10
; i
+
+
)
a
[
i
]
=
i;
int
j
=
i;
//
j = 42
—
end example
]
2
#
If a declaration that is not a name-independent declaration and that binds a name in the block scope
S
of a
(2.1)
compound-statement
of a
lambda-expression
,
function-body
, or
function-try-block
,
(2.2)
substatement of a selection or iteration statement that is not itself a selection or iteration statement, or
(2.3)
handler
of a
function-try-block
potentially conflicts with a declaration whose target scope is the parent scope of
S
, the program is ill-formed
.
[
Example
2
:
if
(
int
x
=
f
(
)
)
{
int
x;
// error: redeclaration of
x
}
else
{
int
x;
// error: redeclaration of
x
}
—
end example
]