[basic.scope.block] (original) (raw)

6 Basics [basic]

6.4.3 Block scope [basic.scope.block]

1

#

Each

introduces a block scopethat 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

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_]