tmp/tmp0vlk44oq/{from.md → to.md}
RENAMED
|
@@ -1,77 +0,0 @@
|
|
| 1 |
-
### Declarative regions and scopes <a id="basic.scope.declarative">[[basic.scope.declarative]]</a>
|
| 2 |
-
|
| 3 |
-
Every name is introduced in some portion of program text called a
|
| 4 |
-
*declarative region*, which is the largest part of the program in which
|
| 5 |
-
that name is valid, that is, in which that name may be used as an
|
| 6 |
-
unqualified name to refer to the same entity. In general, each
|
| 7 |
-
particular name is valid only within some possibly discontiguous portion
|
| 8 |
-
of program text called its *scope*. To determine the scope of a
|
| 9 |
-
declaration, it is sometimes convenient to refer to the *potential
|
| 10 |
-
scope* of a declaration. The scope of a declaration is the same as its
|
| 11 |
-
potential scope unless the potential scope contains another declaration
|
| 12 |
-
of the same name. In that case, the potential scope of the declaration
|
| 13 |
-
in the inner (contained) declarative region is excluded from the scope
|
| 14 |
-
of the declaration in the outer (containing) declarative region.
|
| 15 |
-
|
| 16 |
-
[*Example 1*:
|
| 17 |
-
|
| 18 |
-
In
|
| 19 |
-
|
| 20 |
-
``` cpp
|
| 21 |
-
int j = 24;
|
| 22 |
-
int main() {
|
| 23 |
-
int i = j, j;
|
| 24 |
-
j = 42;
|
| 25 |
-
}
|
| 26 |
-
```
|
| 27 |
-
|
| 28 |
-
the identifier `j` is declared twice as a name (and used twice). The
|
| 29 |
-
declarative region of the first `j` includes the entire example. The
|
| 30 |
-
potential scope of the first `j` begins immediately after that `j` and
|
| 31 |
-
extends to the end of the program, but its (actual) scope excludes the
|
| 32 |
-
text between the `,` and the `}`. The declarative region of the second
|
| 33 |
-
declaration of `j` (the `j` immediately before the semicolon) includes
|
| 34 |
-
all the text between `{` and `}`, but its potential scope excludes the
|
| 35 |
-
declaration of `i`. The scope of the second declaration of `j` is the
|
| 36 |
-
same as its potential scope.
|
| 37 |
-
|
| 38 |
-
— *end example*]
|
| 39 |
-
|
| 40 |
-
The names declared by a declaration are introduced into the scope in
|
| 41 |
-
which the declaration occurs, except that the presence of a `friend`
|
| 42 |
-
specifier [[class.friend]], certain uses of the
|
| 43 |
-
*elaborated-type-specifier* [[dcl.type.elab]], and *using-directive*s
|
| 44 |
-
[[namespace.udir]] alter this general behavior.
|
| 45 |
-
|
| 46 |
-
Given a set of declarations in a single declarative region, each of
|
| 47 |
-
which specifies the same unqualified name,
|
| 48 |
-
|
| 49 |
-
- they shall all refer to the same entity, or all refer to functions and
|
| 50 |
-
function templates; or
|
| 51 |
-
- exactly one declaration shall declare a class name or enumeration name
|
| 52 |
-
that is not a typedef name and the other declarations shall all refer
|
| 53 |
-
to the same variable, non-static data member, or enumerator, or all
|
| 54 |
-
refer to functions and function templates; in this case the class name
|
| 55 |
-
or enumeration name is hidden [[basic.scope.hiding]]. \[*Note 1*: A
|
| 56 |
-
structured binding [[dcl.struct.bind]], namespace name
|
| 57 |
-
[[basic.namespace]], or class template name [[temp.pre]] must be
|
| 58 |
-
unique in its declarative region. — *end note*]
|
| 59 |
-
|
| 60 |
-
[*Note 2*: These restrictions apply to the declarative region into
|
| 61 |
-
which a name is introduced, which is not necessarily the same as the
|
| 62 |
-
region in which the declaration occurs. In particular,
|
| 63 |
-
*elaborated-type-specifier*s [[dcl.type.elab]] and friend declarations
|
| 64 |
-
[[class.friend]] may introduce a (possibly not visible) name into an
|
| 65 |
-
enclosing namespace; these restrictions apply to that region. Local
|
| 66 |
-
extern declarations [[basic.link]] may introduce a name into the
|
| 67 |
-
declarative region where the declaration appears and also introduce a
|
| 68 |
-
(possibly not visible) name into an enclosing namespace; these
|
| 69 |
-
restrictions apply to both regions. — *end note*]
|
| 70 |
-
|
| 71 |
-
For a given declarative region *R* and a point *P* outside *R*, the set
|
| 72 |
-
of *intervening* declarative regions between *P* and *R* comprises all
|
| 73 |
-
declarative regions that are or enclose *R* and do not enclose *P*.
|
| 74 |
-
|
| 75 |
-
[*Note 3*: The name lookup rules are summarized in
|
| 76 |
-
[[basic.lookup]]. — *end note*]
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|