From Jason Turner

[basic.scope.block]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplioydznp/{from.md → to.md} +39 -15
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
- 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 {
 
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 {