tmp/tmpy1slwzr1/{from.md → to.md}
RENAMED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
### General <a id="basic.scope.scope">[[basic.scope.scope]]</a>
|
| 2 |
|
| 3 |
The declarations in a program appear in a number of *scopes* that are in
|
| 4 |
general discontiguous. The *global scope* contains the entire program;
|
| 5 |
every other scope S is introduced by a declaration,
|
| 6 |
-
*parameter-declaration-clause*, *statement*,
|
| 7 |
-
in the following subclauses of [[basic.scope]])
|
| 8 |
-
scope which thereby contains S. An
|
| 9 |
-
|
| 10 |
-
*immediate scope* at that point. A
|
| 11 |
-
point P and a scope S (that does
|
| 12 |
-
but does not contain P.
|
| 13 |
|
| 14 |
Unless otherwise specified:
|
| 15 |
|
| 16 |
- The smallest scope that contains a scope S is the *parent scope* of S.
|
| 17 |
- No two declarations (re)introduce the same entity.
|
|
@@ -19,12 +19,13 @@ Unless otherwise specified:
|
|
| 19 |
[[basic.scope.pdecl]].
|
| 20 |
- A declaration’s *target scope* is the scope it inhabits.
|
| 21 |
- Any names (re)introduced by a declaration are *bound* to it in its
|
| 22 |
target scope.
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
[*Note 1*:
|
| 28 |
|
| 29 |
Special cases include that:
|
| 30 |
|
|
@@ -32,35 +33,36 @@ Special cases include that:
|
|
| 32 |
scopes [[basic.scope.temp]].
|
| 33 |
- Corresponding declarations with appropriate linkage declare the same
|
| 34 |
entity [[basic.link]].
|
| 35 |
- The declaration in a *template-declaration* inhabits the same scope as
|
| 36 |
the *template-declaration*.
|
| 37 |
-
- Friend declarations and declarations of
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
- Block-scope extern declarations target a larger enclosing
|
| 43 |
-
bind a name in their immediate scope
|
|
|
|
| 44 |
- The names of unscoped enumerators are bound in the two innermost
|
| 45 |
enclosing scopes [[dcl.enum]].
|
| 46 |
- A class’s name is also bound in its own scope [[class.pre]].
|
| 47 |
- The names of the members of an anonymous union are bound in the
|
| 48 |
union’s parent scope [[class.union.anon]].
|
| 49 |
|
| 50 |
— *end note*]
|
| 51 |
|
| 52 |
Two non-static member functions have *corresponding object parameters*
|
| 53 |
-
if
|
| 54 |
|
| 55 |
- exactly one is an implicit object member function with no
|
| 56 |
*ref-qualifier* and the types of their object parameters [[dcl.fct]],
|
| 57 |
-
after removing
|
| 58 |
- their object parameters have the same type.
|
| 59 |
|
| 60 |
Two non-static member function templates have *corresponding object
|
| 61 |
-
parameters* if
|
| 62 |
|
| 63 |
- exactly one is an implicit object member function with no
|
| 64 |
*ref-qualifier* and the types of their object parameters, after
|
| 65 |
removing any references, are equivalent, or
|
| 66 |
- the types of their object parameters are equivalent.
|
|
@@ -73,22 +75,26 @@ are non-static members, they have corresponding object parameters.
|
|
| 73 |
|
| 74 |
Two declarations *correspond* if they (re)introduce the same name, both
|
| 75 |
declare constructors, or both declare destructors, unless
|
| 76 |
|
| 77 |
- either is a *using-declarator*, or
|
| 78 |
-
- one declares a type (not a
|
| 79 |
variable, non-static data member other than of an anonymous union
|
| 80 |
[[class.union.anon]], enumerator, function, or function template, or
|
| 81 |
-
- each declares a function or function template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
- both declare functions with the same
|
| 83 |
non-object-parameter-type-list,[^3] equivalent [[temp.over.link]]
|
| 84 |
trailing *requires-clause*s (if any, except as specified in
|
| 85 |
[[temp.friend]]), and, if both are non-static members, they have
|
| 86 |
corresponding object parameters, or
|
| 87 |
- both declare function templates with corresponding signatures and
|
| 88 |
-
|
| 89 |
-
any).
|
| 90 |
|
| 91 |
[*Note 2*:
|
| 92 |
|
| 93 |
Declarations can correspond even if neither binds a name.
|
| 94 |
|
|
@@ -132,17 +138,34 @@ struct X {
|
|
| 132 |
};
|
| 133 |
```
|
| 134 |
|
| 135 |
— *end example*]
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
Two declarations *potentially conflict* if they correspond and cause
|
| 138 |
their shared name to denote different entities [[basic.link]]. The
|
| 139 |
program is ill-formed if, in any scope, a name is bound to two
|
| 140 |
-
declarations that potentially conflict and
|
| 141 |
-
[[basic.lookup]].
|
| 142 |
|
| 143 |
-
[*Note 3*:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
declarations found in multiple scopes (e.g., via *using-directive*s or
|
| 145 |
for operator functions), in which case it is often
|
| 146 |
ambiguous. — *end note*]
|
| 147 |
|
| 148 |
[*Example 3*:
|
|
@@ -158,10 +181,22 @@ namespace A {}
|
|
| 158 |
namespace B = A;
|
| 159 |
namespace B = A; // OK, no effect
|
| 160 |
namespace B = B; // OK, no effect
|
| 161 |
namespace A = B; // OK, no effect
|
| 162 |
namespace B {} // error: different entity for B
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
```
|
| 164 |
|
| 165 |
— *end example*]
|
| 166 |
|
| 167 |
A declaration is *nominable* in a class, class template, or namespace E
|
|
|
|
| 1 |
### General <a id="basic.scope.scope">[[basic.scope.scope]]</a>
|
| 2 |
|
| 3 |
The declarations in a program appear in a number of *scopes* that are in
|
| 4 |
general discontiguous. The *global scope* contains the entire program;
|
| 5 |
every other scope S is introduced by a declaration,
|
| 6 |
+
*parameter-declaration-clause*, *statement*, *handler*, or contract
|
| 7 |
+
assertion (as described in the following subclauses of [[basic.scope]])
|
| 8 |
+
appearing in another scope, which thereby contains S. An
|
| 9 |
+
*enclosing scope* at a program point is any scope that contains it; the
|
| 10 |
+
smallest such scope is said to be the *immediate scope* at that point. A
|
| 11 |
+
scope *intervenes* between a program point P and a scope S (that does
|
| 12 |
+
not contain P) if it is or contains S but does not contain P.
|
| 13 |
|
| 14 |
Unless otherwise specified:
|
| 15 |
|
| 16 |
- The smallest scope that contains a scope S is the *parent scope* of S.
|
| 17 |
- No two declarations (re)introduce the same entity.
|
|
|
|
| 19 |
[[basic.scope.pdecl]].
|
| 20 |
- A declaration’s *target scope* is the scope it inhabits.
|
| 21 |
- Any names (re)introduced by a declaration are *bound* to it in its
|
| 22 |
target scope.
|
| 23 |
|
| 24 |
+
The *host scope* of a declaration is the inhabited scope if that scope
|
| 25 |
+
is a block scope and the target scope otherwise. An entity *belongs* to
|
| 26 |
+
a scope S if S is the target scope of a declaration of the entity.
|
| 27 |
|
| 28 |
[*Note 1*:
|
| 29 |
|
| 30 |
Special cases include that:
|
| 31 |
|
|
|
|
| 33 |
scopes [[basic.scope.temp]].
|
| 34 |
- Corresponding declarations with appropriate linkage declare the same
|
| 35 |
entity [[basic.link]].
|
| 36 |
- The declaration in a *template-declaration* inhabits the same scope as
|
| 37 |
the *template-declaration*.
|
| 38 |
+
- Friend declarations and declarations of template specializations do
|
| 39 |
+
not bind names [[dcl.meaning]]; those with qualified names target a
|
| 40 |
+
specified scope, and other friend declarations and certain
|
| 41 |
+
*elaborated-type-specifier*s [[dcl.type.elab]] target a larger
|
| 42 |
+
enclosing scope.
|
| 43 |
+
- Block-scope extern or function declarations target a larger enclosing
|
| 44 |
+
scope but bind a name in their immediate scope
|
| 45 |
+
[[dcl.meaning.general]].
|
| 46 |
- The names of unscoped enumerators are bound in the two innermost
|
| 47 |
enclosing scopes [[dcl.enum]].
|
| 48 |
- A class’s name is also bound in its own scope [[class.pre]].
|
| 49 |
- The names of the members of an anonymous union are bound in the
|
| 50 |
union’s parent scope [[class.union.anon]].
|
| 51 |
|
| 52 |
— *end note*]
|
| 53 |
|
| 54 |
Two non-static member functions have *corresponding object parameters*
|
| 55 |
+
if
|
| 56 |
|
| 57 |
- exactly one is an implicit object member function with no
|
| 58 |
*ref-qualifier* and the types of their object parameters [[dcl.fct]],
|
| 59 |
+
after removing references, are the same, or
|
| 60 |
- their object parameters have the same type.
|
| 61 |
|
| 62 |
Two non-static member function templates have *corresponding object
|
| 63 |
+
parameters* if
|
| 64 |
|
| 65 |
- exactly one is an implicit object member function with no
|
| 66 |
*ref-qualifier* and the types of their object parameters, after
|
| 67 |
removing any references, are equivalent, or
|
| 68 |
- the types of their object parameters are equivalent.
|
|
|
|
| 75 |
|
| 76 |
Two declarations *correspond* if they (re)introduce the same name, both
|
| 77 |
declare constructors, or both declare destructors, unless
|
| 78 |
|
| 79 |
- either is a *using-declarator*, or
|
| 80 |
+
- one declares a type (not a type alias) and the other declares a
|
| 81 |
variable, non-static data member other than of an anonymous union
|
| 82 |
[[class.union.anon]], enumerator, function, or function template, or
|
| 83 |
+
- each declares a function or function template and they do not declare
|
| 84 |
+
corresponding overloads.
|
| 85 |
+
|
| 86 |
+
Two function or function template declarations declare *corresponding
|
| 87 |
+
overloads* if
|
| 88 |
+
|
| 89 |
- both declare functions with the same
|
| 90 |
non-object-parameter-type-list,[^3] equivalent [[temp.over.link]]
|
| 91 |
trailing *requires-clause*s (if any, except as specified in
|
| 92 |
[[temp.friend]]), and, if both are non-static members, they have
|
| 93 |
corresponding object parameters, or
|
| 94 |
- both declare function templates with corresponding signatures and
|
| 95 |
+
equivalent *template-head*s and trailing *requires-clause*s (if any).
|
|
|
|
| 96 |
|
| 97 |
[*Note 2*:
|
| 98 |
|
| 99 |
Declarations can correspond even if neither binds a name.
|
| 100 |
|
|
|
|
| 138 |
};
|
| 139 |
```
|
| 140 |
|
| 141 |
— *end example*]
|
| 142 |
|
| 143 |
+
A declaration is *name-independent* if its name is `_`
|
| 144 |
+
(U+005f (low line)) and it declares
|
| 145 |
+
|
| 146 |
+
- a variable with automatic storage duration,
|
| 147 |
+
- a structured binding with no *storage-class-specifier* and not
|
| 148 |
+
inhabiting a namespace scope,
|
| 149 |
+
- a result binding [[dcl.contract.res]],
|
| 150 |
+
- the variable introduced by an *init-capture*, or
|
| 151 |
+
- a non-static data member of other than an anonymous union.
|
| 152 |
+
|
| 153 |
+
*Recommended practice:* Implementations should not emit a warning that a
|
| 154 |
+
name-independent declaration is used or unused.
|
| 155 |
+
|
| 156 |
Two declarations *potentially conflict* if they correspond and cause
|
| 157 |
their shared name to denote different entities [[basic.link]]. The
|
| 158 |
program is ill-formed if, in any scope, a name is bound to two
|
| 159 |
+
declarations A and B that potentially conflict and A precedes B
|
| 160 |
+
[[basic.lookup]], unless B is name-independent.
|
| 161 |
|
| 162 |
+
[*Note 3*: An *id-expression* that names a unique name-independent
|
| 163 |
+
declaration is usable until an additional declaration of the same name
|
| 164 |
+
is introduced in the same scope [[basic.lookup.general]]. — *end note*]
|
| 165 |
+
|
| 166 |
+
[*Note 4*: Overload resolution can consider potentially conflicting
|
| 167 |
declarations found in multiple scopes (e.g., via *using-directive*s or
|
| 168 |
for operator functions), in which case it is often
|
| 169 |
ambiguous. — *end note*]
|
| 170 |
|
| 171 |
[*Example 3*:
|
|
|
|
| 181 |
namespace B = A;
|
| 182 |
namespace B = A; // OK, no effect
|
| 183 |
namespace B = B; // OK, no effect
|
| 184 |
namespace A = B; // OK, no effect
|
| 185 |
namespace B {} // error: different entity for B
|
| 186 |
+
|
| 187 |
+
void g() {
|
| 188 |
+
int _;
|
| 189 |
+
_ = 0; // OK
|
| 190 |
+
int _; // OK, name-independent declaration
|
| 191 |
+
_ = 0; // error: two non-function declarations in the lookup set
|
| 192 |
+
}
|
| 193 |
+
void h () {
|
| 194 |
+
int _; // #1
|
| 195 |
+
_ ++; // OK
|
| 196 |
+
static int _; // error: conflicts with #1 because static variables are not name-independent
|
| 197 |
+
}
|
| 198 |
```
|
| 199 |
|
| 200 |
— *end example*]
|
| 201 |
|
| 202 |
A declaration is *nominable* in a class, class template, or namespace E
|