tmp/tmpz883t1hg/{from.md → to.md}
RENAMED
|
@@ -3,17 +3,17 @@
|
|
| 3 |
### General <a id="basic.scope.scope">[[basic.scope.scope]]</a>
|
| 4 |
|
| 5 |
The declarations in a program appear in a number of *scopes* that are in
|
| 6 |
general discontiguous. The *global scope* contains the entire program;
|
| 7 |
every other scope S is introduced by a declaration,
|
| 8 |
-
*parameter-declaration-clause*, *statement*,
|
| 9 |
-
in the following subclauses of [[basic.scope]])
|
| 10 |
-
scope which thereby contains S. An
|
| 11 |
-
|
| 12 |
-
*immediate scope* at that point. A
|
| 13 |
-
point P and a scope S (that does
|
| 14 |
-
but does not contain P.
|
| 15 |
|
| 16 |
Unless otherwise specified:
|
| 17 |
|
| 18 |
- The smallest scope that contains a scope S is the *parent scope* of S.
|
| 19 |
- No two declarations (re)introduce the same entity.
|
|
@@ -21,12 +21,13 @@ Unless otherwise specified:
|
|
| 21 |
[[basic.scope.pdecl]].
|
| 22 |
- A declaration’s *target scope* is the scope it inhabits.
|
| 23 |
- Any names (re)introduced by a declaration are *bound* to it in its
|
| 24 |
target scope.
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
[*Note 1*:
|
| 30 |
|
| 31 |
Special cases include that:
|
| 32 |
|
|
@@ -34,35 +35,36 @@ Special cases include that:
|
|
| 34 |
scopes [[basic.scope.temp]].
|
| 35 |
- Corresponding declarations with appropriate linkage declare the same
|
| 36 |
entity [[basic.link]].
|
| 37 |
- The declaration in a *template-declaration* inhabits the same scope as
|
| 38 |
the *template-declaration*.
|
| 39 |
-
- Friend declarations and declarations of
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
- Block-scope extern declarations target a larger enclosing
|
| 45 |
-
bind a name in their immediate scope
|
|
|
|
| 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
|
| 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,22 +77,26 @@ are non-static members, they have corresponding object parameters.
|
|
| 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
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
- both declare functions with the same
|
| 85 |
non-object-parameter-type-list,[^3] equivalent [[temp.over.link]]
|
| 86 |
trailing *requires-clause*s (if any, except as specified in
|
| 87 |
[[temp.friend]]), and, if both are non-static members, they have
|
| 88 |
corresponding object parameters, or
|
| 89 |
- both declare function templates with corresponding signatures and
|
| 90 |
-
|
| 91 |
-
any).
|
| 92 |
|
| 93 |
[*Note 2*:
|
| 94 |
|
| 95 |
Declarations can correspond even if neither binds a name.
|
| 96 |
|
|
@@ -134,17 +140,34 @@ struct X {
|
|
| 134 |
};
|
| 135 |
```
|
| 136 |
|
| 137 |
— *end example*]
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
Two declarations *potentially conflict* if they correspond and cause
|
| 140 |
their shared name to denote different entities [[basic.link]]. The
|
| 141 |
program is ill-formed if, in any scope, a name is bound to two
|
| 142 |
-
declarations that potentially conflict and
|
| 143 |
-
[[basic.lookup]].
|
| 144 |
|
| 145 |
-
[*Note 3*:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
declarations found in multiple scopes (e.g., via *using-directive*s or
|
| 147 |
for operator functions), in which case it is often
|
| 148 |
ambiguous. — *end note*]
|
| 149 |
|
| 150 |
[*Example 3*:
|
|
@@ -160,10 +183,22 @@ namespace A {}
|
|
| 160 |
namespace B = A;
|
| 161 |
namespace B = A; // OK, no effect
|
| 162 |
namespace B = B; // OK, no effect
|
| 163 |
namespace A = B; // OK, no effect
|
| 164 |
namespace B {} // error: different entity for B
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
```
|
| 166 |
|
| 167 |
— *end example*]
|
| 168 |
|
| 169 |
A declaration is *nominable* in a class, class template, or namespace E
|
|
@@ -286,11 +321,13 @@ variable [[dcl.fct.def.general]] is immediately before the
|
|
| 286 |
The locus of the declaration of a structured binding [[dcl.struct.bind]]
|
| 287 |
is immediately after the *identifier-list* of the structured binding
|
| 288 |
declaration.
|
| 289 |
|
| 290 |
The locus of a *for-range-declaration* of a range-based `for` statement
|
| 291 |
-
[[stmt.ranged]] is immediately after the *for-range-initializer*.
|
|
|
|
|
|
|
| 292 |
|
| 293 |
The locus of a *template-parameter* is immediately after it.
|
| 294 |
|
| 295 |
[*Example 5*:
|
| 296 |
|
|
@@ -302,12 +339,15 @@ template<class T
|
|
| 302 |
N = 0> struct A { };
|
| 303 |
```
|
| 304 |
|
| 305 |
— *end example*]
|
| 306 |
|
|
|
|
|
|
|
|
|
|
| 307 |
The locus of a *concept-definition* is immediately after its
|
| 308 |
-
concept-name [[temp.concept]].
|
| 309 |
|
| 310 |
[*Note 3*: The *constraint-expression* cannot use the
|
| 311 |
*concept-name*. — *end note*]
|
| 312 |
|
| 313 |
The locus of a *namespace-definition* with an *identifier* is
|
|
@@ -328,11 +368,12 @@ but they do not bind names in it. — *end note*]
|
|
| 328 |
|
| 329 |
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 330 |
|
| 331 |
Each
|
| 332 |
|
| 333 |
-
- selection
|
|
|
|
| 334 |
- substatement of such a statement,
|
| 335 |
- *handler* [[except.pre]], or
|
| 336 |
- compound statement [[stmt.block]] that is not the *compound-statement*
|
| 337 |
of a *handler*
|
| 338 |
|
|
@@ -355,11 +396,12 @@ for (int i = 0; i < 10; i++)
|
|
| 355 |
int j = i; // j = 42
|
| 356 |
```
|
| 357 |
|
| 358 |
— *end example*]
|
| 359 |
|
| 360 |
-
If a declaration
|
|
|
|
| 361 |
|
| 362 |
- *compound-statement* of a *lambda-expression*, *function-body*, or
|
| 363 |
*function-try-block*,
|
| 364 |
- substatement of a selection or iteration statement that is not itself
|
| 365 |
a selection or iteration statement, or
|
|
@@ -401,11 +443,11 @@ A *parameter-declaration-clause* P introduces a
|
|
| 401 |
parameter scope is nested within its class’s scope. — *end note*]
|
| 402 |
- If P is associated with a *lambda-declarator*, its scope extends to
|
| 403 |
the end of the *compound-statement* in the *lambda-expression*.
|
| 404 |
- If P is associated with a *requirement-parameter-list*, its scope
|
| 405 |
extends to the end of the *requirement-body* of the
|
| 406 |
-
requires-expression.
|
| 407 |
- If P is associated with a *deduction-guide*, its scope extends to the
|
| 408 |
end of the *deduction-guide*.
|
| 409 |
|
| 410 |
### Lambda scope <a id="basic.scope.lambda">[[basic.scope.lambda]]</a>
|
| 411 |
|
|
@@ -472,13 +514,13 @@ Any declaration of an enumeration E introduces an *enumeration scope*
|
|
| 472 |
that includes the *enumerator-list* of the *enum-specifier* for E (if
|
| 473 |
any).
|
| 474 |
|
| 475 |
### Template parameter scope <a id="basic.scope.temp">[[basic.scope.temp]]</a>
|
| 476 |
|
| 477 |
-
Each
|
| 478 |
-
*
|
| 479 |
-
*template-parameter*.
|
| 480 |
|
| 481 |
Each *template-declaration* D introduces a template parameter scope that
|
| 482 |
extends from the beginning of its *template-parameter-list* to the end
|
| 483 |
of the *template-declaration*. Any declaration outside the
|
| 484 |
*template-parameter-list* that would inhabit that scope instead inhabits
|
|
@@ -488,5 +530,21 @@ not a template parameter scope.
|
|
| 488 |
|
| 489 |
[*Note 1*: Therefore, only template parameters belong to a template
|
| 490 |
parameter scope, and only template parameter scopes have a template
|
| 491 |
parameter scope as a parent scope. — *end note*]
|
| 492 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
### General <a id="basic.scope.scope">[[basic.scope.scope]]</a>
|
| 4 |
|
| 5 |
The declarations in a program appear in a number of *scopes* that are in
|
| 6 |
general discontiguous. The *global scope* contains the entire program;
|
| 7 |
every other scope S is introduced by a declaration,
|
| 8 |
+
*parameter-declaration-clause*, *statement*, *handler*, or contract
|
| 9 |
+
assertion (as described in the following subclauses of [[basic.scope]])
|
| 10 |
+
appearing in another scope, which thereby contains S. An
|
| 11 |
+
*enclosing scope* at a program point is any scope that contains it; the
|
| 12 |
+
smallest such scope is said to be the *immediate scope* at that point. A
|
| 13 |
+
scope *intervenes* between a program point P and a scope S (that does
|
| 14 |
+
not contain P) if it is or contains S but does not contain P.
|
| 15 |
|
| 16 |
Unless otherwise specified:
|
| 17 |
|
| 18 |
- The smallest scope that contains a scope S is the *parent scope* of S.
|
| 19 |
- No two declarations (re)introduce the same entity.
|
|
|
|
| 21 |
[[basic.scope.pdecl]].
|
| 22 |
- A declaration’s *target scope* is the scope it inhabits.
|
| 23 |
- Any names (re)introduced by a declaration are *bound* to it in its
|
| 24 |
target scope.
|
| 25 |
|
| 26 |
+
The *host scope* of a declaration is the inhabited scope if that scope
|
| 27 |
+
is a block scope and the target scope otherwise. An entity *belongs* to
|
| 28 |
+
a scope S if S is the target scope of a declaration of the entity.
|
| 29 |
|
| 30 |
[*Note 1*:
|
| 31 |
|
| 32 |
Special cases include that:
|
| 33 |
|
|
|
|
| 35 |
scopes [[basic.scope.temp]].
|
| 36 |
- Corresponding declarations with appropriate linkage declare the same
|
| 37 |
entity [[basic.link]].
|
| 38 |
- The declaration in a *template-declaration* inhabits the same scope as
|
| 39 |
the *template-declaration*.
|
| 40 |
+
- Friend declarations and declarations of template specializations do
|
| 41 |
+
not bind names [[dcl.meaning]]; those with qualified names target a
|
| 42 |
+
specified scope, and other friend declarations and certain
|
| 43 |
+
*elaborated-type-specifier*s [[dcl.type.elab]] target a larger
|
| 44 |
+
enclosing scope.
|
| 45 |
+
- Block-scope extern or function declarations target a larger enclosing
|
| 46 |
+
scope but bind a name in their immediate scope
|
| 47 |
+
[[dcl.meaning.general]].
|
| 48 |
- The names of unscoped enumerators are bound in the two innermost
|
| 49 |
enclosing scopes [[dcl.enum]].
|
| 50 |
- A class’s name is also bound in its own scope [[class.pre]].
|
| 51 |
- The names of the members of an anonymous union are bound in the
|
| 52 |
union’s parent scope [[class.union.anon]].
|
| 53 |
|
| 54 |
— *end note*]
|
| 55 |
|
| 56 |
Two non-static member functions have *corresponding object parameters*
|
| 57 |
+
if
|
| 58 |
|
| 59 |
- exactly one is an implicit object member function with no
|
| 60 |
*ref-qualifier* and the types of their object parameters [[dcl.fct]],
|
| 61 |
+
after removing references, are the same, or
|
| 62 |
- their object parameters have the same type.
|
| 63 |
|
| 64 |
Two non-static member function templates have *corresponding object
|
| 65 |
+
parameters* if
|
| 66 |
|
| 67 |
- exactly one is an implicit object member function with no
|
| 68 |
*ref-qualifier* and the types of their object parameters, after
|
| 69 |
removing any references, are equivalent, or
|
| 70 |
- the types of their object parameters are equivalent.
|
|
|
|
| 77 |
|
| 78 |
Two declarations *correspond* if they (re)introduce the same name, both
|
| 79 |
declare constructors, or both declare destructors, unless
|
| 80 |
|
| 81 |
- either is a *using-declarator*, or
|
| 82 |
+
- one declares a type (not a type alias) and the other declares a
|
| 83 |
variable, non-static data member other than of an anonymous union
|
| 84 |
[[class.union.anon]], enumerator, function, or function template, or
|
| 85 |
+
- each declares a function or function template and they do not declare
|
| 86 |
+
corresponding overloads.
|
| 87 |
+
|
| 88 |
+
Two function or function template declarations declare *corresponding
|
| 89 |
+
overloads* if
|
| 90 |
+
|
| 91 |
- both declare functions with the same
|
| 92 |
non-object-parameter-type-list,[^3] equivalent [[temp.over.link]]
|
| 93 |
trailing *requires-clause*s (if any, except as specified in
|
| 94 |
[[temp.friend]]), and, if both are non-static members, they have
|
| 95 |
corresponding object parameters, or
|
| 96 |
- both declare function templates with corresponding signatures and
|
| 97 |
+
equivalent *template-head*s and trailing *requires-clause*s (if any).
|
|
|
|
| 98 |
|
| 99 |
[*Note 2*:
|
| 100 |
|
| 101 |
Declarations can correspond even if neither binds a name.
|
| 102 |
|
|
|
|
| 140 |
};
|
| 141 |
```
|
| 142 |
|
| 143 |
— *end example*]
|
| 144 |
|
| 145 |
+
A declaration is *name-independent* if its name is `_`
|
| 146 |
+
(U+005f (low line)) and it declares
|
| 147 |
+
|
| 148 |
+
- a variable with automatic storage duration,
|
| 149 |
+
- a structured binding with no *storage-class-specifier* and not
|
| 150 |
+
inhabiting a namespace scope,
|
| 151 |
+
- a result binding [[dcl.contract.res]],
|
| 152 |
+
- the variable introduced by an *init-capture*, or
|
| 153 |
+
- a non-static data member of other than an anonymous union.
|
| 154 |
+
|
| 155 |
+
*Recommended practice:* Implementations should not emit a warning that a
|
| 156 |
+
name-independent declaration is used or unused.
|
| 157 |
+
|
| 158 |
Two declarations *potentially conflict* if they correspond and cause
|
| 159 |
their shared name to denote different entities [[basic.link]]. The
|
| 160 |
program is ill-formed if, in any scope, a name is bound to two
|
| 161 |
+
declarations A and B that potentially conflict and A precedes B
|
| 162 |
+
[[basic.lookup]], unless B is name-independent.
|
| 163 |
|
| 164 |
+
[*Note 3*: An *id-expression* that names a unique name-independent
|
| 165 |
+
declaration is usable until an additional declaration of the same name
|
| 166 |
+
is introduced in the same scope [[basic.lookup.general]]. — *end note*]
|
| 167 |
+
|
| 168 |
+
[*Note 4*: Overload resolution can consider potentially conflicting
|
| 169 |
declarations found in multiple scopes (e.g., via *using-directive*s or
|
| 170 |
for operator functions), in which case it is often
|
| 171 |
ambiguous. — *end note*]
|
| 172 |
|
| 173 |
[*Example 3*:
|
|
|
|
| 183 |
namespace B = A;
|
| 184 |
namespace B = A; // OK, no effect
|
| 185 |
namespace B = B; // OK, no effect
|
| 186 |
namespace A = B; // OK, no effect
|
| 187 |
namespace B {} // error: different entity for B
|
| 188 |
+
|
| 189 |
+
void g() {
|
| 190 |
+
int _;
|
| 191 |
+
_ = 0; // OK
|
| 192 |
+
int _; // OK, name-independent declaration
|
| 193 |
+
_ = 0; // error: two non-function declarations in the lookup set
|
| 194 |
+
}
|
| 195 |
+
void h () {
|
| 196 |
+
int _; // #1
|
| 197 |
+
_ ++; // OK
|
| 198 |
+
static int _; // error: conflicts with #1 because static variables are not name-independent
|
| 199 |
+
}
|
| 200 |
```
|
| 201 |
|
| 202 |
— *end example*]
|
| 203 |
|
| 204 |
A declaration is *nominable* in a class, class template, or namespace E
|
|
|
|
| 321 |
The locus of the declaration of a structured binding [[dcl.struct.bind]]
|
| 322 |
is immediately after the *identifier-list* of the structured binding
|
| 323 |
declaration.
|
| 324 |
|
| 325 |
The locus of a *for-range-declaration* of a range-based `for` statement
|
| 326 |
+
[[stmt.ranged]] is immediately after the *for-range-initializer*. The
|
| 327 |
+
locus of a *for-range-declaration* of an *expansion-statement*
|
| 328 |
+
[[stmt.expand]] is immediately after the *expansion-initializer*.
|
| 329 |
|
| 330 |
The locus of a *template-parameter* is immediately after it.
|
| 331 |
|
| 332 |
[*Example 5*:
|
| 333 |
|
|
|
|
| 339 |
N = 0> struct A { };
|
| 340 |
```
|
| 341 |
|
| 342 |
— *end example*]
|
| 343 |
|
| 344 |
+
The locus of a *result-name-introducer* [[dcl.contract.res]] is
|
| 345 |
+
immediately after it.
|
| 346 |
+
|
| 347 |
The locus of a *concept-definition* is immediately after its
|
| 348 |
+
*concept-name* [[temp.concept]].
|
| 349 |
|
| 350 |
[*Note 3*: The *constraint-expression* cannot use the
|
| 351 |
*concept-name*. — *end note*]
|
| 352 |
|
| 353 |
The locus of a *namespace-definition* with an *identifier* is
|
|
|
|
| 368 |
|
| 369 |
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 370 |
|
| 371 |
Each
|
| 372 |
|
| 373 |
+
- selection, iteration, or expansion statement
|
| 374 |
+
[[stmt.select]], [[stmt.iter]], [[stmt.expand]],
|
| 375 |
- substatement of such a statement,
|
| 376 |
- *handler* [[except.pre]], or
|
| 377 |
- compound statement [[stmt.block]] that is not the *compound-statement*
|
| 378 |
of a *handler*
|
| 379 |
|
|
|
|
| 396 |
int j = i; // j = 42
|
| 397 |
```
|
| 398 |
|
| 399 |
— *end example*]
|
| 400 |
|
| 401 |
+
If a declaration that is not a name-independent declaration and that
|
| 402 |
+
binds a name in the block scope S of a
|
| 403 |
|
| 404 |
- *compound-statement* of a *lambda-expression*, *function-body*, or
|
| 405 |
*function-try-block*,
|
| 406 |
- substatement of a selection or iteration statement that is not itself
|
| 407 |
a selection or iteration statement, or
|
|
|
|
| 443 |
parameter scope is nested within its class’s scope. — *end note*]
|
| 444 |
- If P is associated with a *lambda-declarator*, its scope extends to
|
| 445 |
the end of the *compound-statement* in the *lambda-expression*.
|
| 446 |
- If P is associated with a *requirement-parameter-list*, its scope
|
| 447 |
extends to the end of the *requirement-body* of the
|
| 448 |
+
*requires-expression*.
|
| 449 |
- If P is associated with a *deduction-guide*, its scope extends to the
|
| 450 |
end of the *deduction-guide*.
|
| 451 |
|
| 452 |
### Lambda scope <a id="basic.scope.lambda">[[basic.scope.lambda]]</a>
|
| 453 |
|
|
|
|
| 514 |
that includes the *enumerator-list* of the *enum-specifier* for E (if
|
| 515 |
any).
|
| 516 |
|
| 517 |
### Template parameter scope <a id="basic.scope.temp">[[basic.scope.temp]]</a>
|
| 518 |
|
| 519 |
+
Each *type-tt-parameter*, *variable-tt-parameter*, and
|
| 520 |
+
*concept-tt-parameter* introduces a *template parameter scope* that
|
| 521 |
+
includes the *template-head* of the *template-parameter*.
|
| 522 |
|
| 523 |
Each *template-declaration* D introduces a template parameter scope that
|
| 524 |
extends from the beginning of its *template-parameter-list* to the end
|
| 525 |
of the *template-declaration*. Any declaration outside the
|
| 526 |
*template-parameter-list* that would inhabit that scope instead inhabits
|
|
|
|
| 530 |
|
| 531 |
[*Note 1*: Therefore, only template parameters belong to a template
|
| 532 |
parameter scope, and only template parameter scopes have a template
|
| 533 |
parameter scope as a parent scope. — *end note*]
|
| 534 |
|
| 535 |
+
### Contract-assertion scope <a id="basic.scope.contract">[[basic.scope.contract]]</a>
|
| 536 |
+
|
| 537 |
+
Each contract assertion [[basic.contract]] C introduces a
|
| 538 |
+
*contract-assertion scope* that includes C.
|
| 539 |
+
|
| 540 |
+
If a *result-name-introducer* [[dcl.contract.res]] that is not
|
| 541 |
+
name-independent [[basic.scope.scope]] and whose enclosing postcondition
|
| 542 |
+
assertion is associated with a function `F` potentially conflicts with a
|
| 543 |
+
declaration whose target scope is
|
| 544 |
+
|
| 545 |
+
- the function parameter scope of `F` or
|
| 546 |
+
- if associated with a *lambda-declarator*, the nearest enclosing lambda
|
| 547 |
+
scope of the precondition assertion [[expr.prim.lambda]],
|
| 548 |
+
|
| 549 |
+
the program is ill-formed.
|
| 550 |
+
|