tmp/tmplioydznp/{from.md → to.md}
RENAMED
|
@@ -1,25 +1,49 @@
|
|
| 1 |
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
*handler*
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
statement, any of the outermost blocks) of the controlled statement.
|
| 18 |
|
| 19 |
[*Example 1*:
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
``` cpp
|
| 22 |
if (int x = f()) {
|
| 23 |
int x; // error: redeclaration of x
|
| 24 |
}
|
| 25 |
else {
|
|
|
|
| 1 |
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 2 |
|
| 3 |
+
Each
|
| 4 |
+
|
| 5 |
+
- selection or iteration statement [[stmt.select]], [[stmt.iter]],
|
| 6 |
+
- substatement of such a statement,
|
| 7 |
+
- *handler* [[except.pre]], or
|
| 8 |
+
- compound statement [[stmt.block]] that is not the *compound-statement*
|
| 9 |
+
of a *handler*
|
| 10 |
+
|
| 11 |
+
introduces a *block scope* that includes that statement or *handler*.
|
| 12 |
+
|
| 13 |
+
[*Note 1*: A substatement that is also a block has only one
|
| 14 |
+
scope. — *end note*]
|
| 15 |
+
|
| 16 |
+
A variable that belongs to a block scope is a *block variable*.
|
|
|
|
| 17 |
|
| 18 |
[*Example 1*:
|
| 19 |
|
| 20 |
+
``` cpp
|
| 21 |
+
int i = 42;
|
| 22 |
+
int a[10];
|
| 23 |
+
|
| 24 |
+
for (int i = 0; i < 10; i++)
|
| 25 |
+
a[i] = i;
|
| 26 |
+
|
| 27 |
+
int j = i; // j = 42
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
— *end example*]
|
| 31 |
+
|
| 32 |
+
If a declaration whose target scope is the block scope S of a
|
| 33 |
+
|
| 34 |
+
- *compound-statement* of a *lambda-expression*, *function-body*, or
|
| 35 |
+
*function-try-block*,
|
| 36 |
+
- substatement of a selection or iteration statement that is not itself
|
| 37 |
+
a selection or iteration statement, or
|
| 38 |
+
- *handler* of a *function-try-block*
|
| 39 |
+
|
| 40 |
+
potentially conflicts with a declaration whose target scope is the
|
| 41 |
+
parent scope of S, the program is ill-formed.
|
| 42 |
+
|
| 43 |
+
[*Example 2*:
|
| 44 |
+
|
| 45 |
``` cpp
|
| 46 |
if (int x = f()) {
|
| 47 |
int x; // error: redeclaration of x
|
| 48 |
}
|
| 49 |
else {
|