tmp/tmplmztj525/{from.md → to.md}
RENAMED
|
@@ -1,30 +1,31 @@
|
|
| 1 |
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 2 |
|
| 3 |
-
A name declared in a block
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
The potential scope of a function parameter name (including one
|
| 9 |
-
appearing in a *lambda-declarator*) or of a function-local predefined
|
| 10 |
-
variable in a function definition ([[dcl.fct.def]]) begins at its point
|
| 11 |
-
of declaration. If the function has a *function-try-block* the potential
|
| 12 |
-
scope of a parameter or of a function-local predefined variable ends at
|
| 13 |
-
the end of the last associated handler, otherwise it ends at the end of
|
| 14 |
-
the outermost block of the function definition. A parameter name shall
|
| 15 |
-
not be redeclared in the outermost block of the function definition nor
|
| 16 |
-
in the outermost block of any handler associated with a
|
| 17 |
-
*function-try-block*.
|
| 18 |
|
| 19 |
The name declared in an *exception-declaration* is local to the
|
| 20 |
*handler* and shall not be redeclared in the outermost block of the
|
| 21 |
*handler*.
|
| 22 |
|
| 23 |
Names declared in the *init-statement*, the *for-range-declaration*, and
|
| 24 |
in the *condition* of `if`, `while`, `for`, and `switch` statements are
|
| 25 |
local to the `if`, `while`, `for`, or `switch` statement (including the
|
| 26 |
controlled statement), and shall not be redeclared in a subsequent
|
| 27 |
condition of that statement nor in the outermost block (or, for the `if`
|
| 28 |
-
statement, any of the outermost blocks) of the controlled statement
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
|
|
|
| 1 |
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 2 |
|
| 3 |
+
A name declared in a block [[stmt.block]] is local to that block; it has
|
| 4 |
+
*block scope*. Its potential scope begins at its point of declaration
|
| 5 |
+
[[basic.scope.pdecl]] and ends at the end of its block. A variable
|
| 6 |
+
declared at block scope is a *local variable*.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
The name declared in an *exception-declaration* is local to the
|
| 9 |
*handler* and shall not be redeclared in the outermost block of the
|
| 10 |
*handler*.
|
| 11 |
|
| 12 |
Names declared in the *init-statement*, the *for-range-declaration*, and
|
| 13 |
in the *condition* of `if`, `while`, `for`, and `switch` statements are
|
| 14 |
local to the `if`, `while`, `for`, or `switch` statement (including the
|
| 15 |
controlled statement), and shall not be redeclared in a subsequent
|
| 16 |
condition of that statement nor in the outermost block (or, for the `if`
|
| 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 {
|
| 26 |
+
int x; // error: redeclaration of x
|
| 27 |
+
}
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
— *end example*]
|
| 31 |
|