- tmp/tmp5n_g6vyg/{from.md → to.md} +342 -419
tmp/tmp5n_g6vyg/{from.md → to.md}
RENAMED
|
@@ -1,89 +1,206 @@
|
|
| 1 |
## Scope <a id="basic.scope">[[basic.scope]]</a>
|
| 2 |
|
| 3 |
-
###
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
scope*
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
[*Example 1*:
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
-
int
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
```
|
| 29 |
|
| 30 |
-
the
|
| 31 |
-
|
| 32 |
-
potential scope of the first `j` begins immediately after that `j` and
|
| 33 |
-
extends to the end of the program, but its (actual) scope excludes the
|
| 34 |
-
text between the `,` and the `}`. The declarative region of the second
|
| 35 |
-
declaration of `j` (the `j` immediately before the semicolon) includes
|
| 36 |
-
all the text between `{` and `}`, but its potential scope excludes the
|
| 37 |
-
declaration of `i`. The scope of the second declaration of `j` is the
|
| 38 |
-
same as its potential scope.
|
| 39 |
|
| 40 |
— *end example*]
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
[[namespace.udir]] alter this general behavior.
|
| 47 |
-
|
| 48 |
-
Given a set of declarations in a single declarative region, each of
|
| 49 |
-
which specifies the same unqualified name,
|
| 50 |
-
|
| 51 |
-
- they shall all refer to the same entity, or all refer to functions and
|
| 52 |
-
function templates; or
|
| 53 |
-
- exactly one declaration shall declare a class name or enumeration name
|
| 54 |
-
that is not a typedef name and the other declarations shall all refer
|
| 55 |
-
to the same variable, non-static data member, or enumerator, or all
|
| 56 |
-
refer to functions and function templates; in this case the class name
|
| 57 |
-
or enumeration name is hidden [[basic.scope.hiding]]. \[*Note 1*: A
|
| 58 |
-
structured binding [[dcl.struct.bind]], namespace name
|
| 59 |
-
[[basic.namespace]], or class template name [[temp.pre]] must be
|
| 60 |
-
unique in its declarative region. — *end note*]
|
| 61 |
-
|
| 62 |
-
[*Note 2*: These restrictions apply to the declarative region into
|
| 63 |
-
which a name is introduced, which is not necessarily the same as the
|
| 64 |
-
region in which the declaration occurs. In particular,
|
| 65 |
-
*elaborated-type-specifier*s [[dcl.type.elab]] and friend declarations
|
| 66 |
-
[[class.friend]] may introduce a (possibly not visible) name into an
|
| 67 |
-
enclosing namespace; these restrictions apply to that region. Local
|
| 68 |
-
extern declarations [[basic.link]] may introduce a name into the
|
| 69 |
-
declarative region where the declaration appears and also introduce a
|
| 70 |
-
(possibly not visible) name into an enclosing namespace; these
|
| 71 |
-
restrictions apply to both regions. — *end note*]
|
| 72 |
-
|
| 73 |
-
For a given declarative region *R* and a point *P* outside *R*, the set
|
| 74 |
-
of *intervening* declarative regions between *P* and *R* comprises all
|
| 75 |
-
declarative regions that are or enclose *R* and do not enclose *P*.
|
| 76 |
-
|
| 77 |
-
[*Note 3*: The name lookup rules are summarized in
|
| 78 |
-
[[basic.lookup]]. — *end note*]
|
| 79 |
|
| 80 |
### Point of declaration <a id="basic.scope.pdecl">[[basic.scope.pdecl]]</a>
|
| 81 |
|
| 82 |
-
The *
|
| 83 |
-
declarator [[dcl.decl]]
|
| 84 |
-
noted below.
|
| 85 |
|
| 86 |
[*Example 1*:
|
| 87 |
|
| 88 |
``` cpp
|
| 89 |
unsigned char x = 12;
|
|
@@ -96,12 +213,12 @@ because the initializer accesses the second `x` outside its lifetime
|
|
| 96 |
|
| 97 |
— *end example*]
|
| 98 |
|
| 99 |
[*Note 1*:
|
| 100 |
|
| 101 |
-
A name from an outer scope remains visible up to the
|
| 102 |
-
declaration
|
| 103 |
|
| 104 |
[*Example 2*:
|
| 105 |
|
| 106 |
``` cpp
|
| 107 |
const int i = 2;
|
|
@@ -112,25 +229,21 @@ declares a block-scope array of two integers.
|
|
| 112 |
|
| 113 |
— *end example*]
|
| 114 |
|
| 115 |
— *end note*]
|
| 116 |
|
| 117 |
-
The
|
| 118 |
-
|
| 119 |
-
*
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
point of declaration of an alias or alias template immediately follows
|
| 124 |
-
the *defining-type-id* to which the alias refers.
|
| 125 |
|
| 126 |
-
The
|
| 127 |
-
|
| 128 |
-
[[namespace.udecl]].
|
| 129 |
|
| 130 |
-
The
|
| 131 |
-
*enumerator-definition*.
|
| 132 |
|
| 133 |
[*Example 3*:
|
| 134 |
|
| 135 |
``` cpp
|
| 136 |
const int x = 12;
|
|
@@ -140,113 +253,125 @@ const int x = 12;
|
|
| 140 |
Here, the enumerator `x` is initialized with the value of the constant
|
| 141 |
`x`, namely 12.
|
| 142 |
|
| 143 |
— *end example*]
|
| 144 |
|
| 145 |
-
After the point of declaration of a class member, the member name can be
|
| 146 |
-
looked up in the scope of its class.
|
| 147 |
-
|
| 148 |
[*Note 2*:
|
| 149 |
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
| 151 |
|
| 152 |
``` cpp
|
| 153 |
struct X {
|
| 154 |
enum E { z = 16 };
|
| 155 |
int b[X::z]; // OK
|
| 156 |
};
|
| 157 |
```
|
| 158 |
|
|
|
|
|
|
|
| 159 |
— *end note*]
|
| 160 |
|
| 161 |
-
The
|
| 162 |
-
|
| 163 |
|
| 164 |
-
|
| 165 |
-
``` bnf
|
| 166 |
-
class-key attribute-specifier-seqₒₚₜ identifier ';'
|
| 167 |
-
```
|
| 168 |
-
|
| 169 |
-
the *identifier* is declared to be a *class-name* in the scope that
|
| 170 |
-
contains the declaration, otherwise
|
| 171 |
-
- for an *elaborated-type-specifier* of the form
|
| 172 |
-
``` bnf
|
| 173 |
-
class-key identifier
|
| 174 |
-
```
|
| 175 |
-
|
| 176 |
-
if the *elaborated-type-specifier* is used in the *decl-specifier-seq*
|
| 177 |
-
or *parameter-declaration-clause* of a function defined in namespace
|
| 178 |
-
scope, the *identifier* is declared as a *class-name* in the namespace
|
| 179 |
-
that contains the declaration; otherwise, except as a friend
|
| 180 |
-
declaration, the *identifier* is declared in the smallest namespace or
|
| 181 |
-
block scope that contains the declaration.
|
| 182 |
-
\[*Note 3*: These rules also apply within templates. — *end note*]
|
| 183 |
-
\[*Note 4*: Other forms of *elaborated-type-specifier* do not declare
|
| 184 |
-
a new name, and therefore must refer to an existing *type-name*. See
|
| 185 |
-
[[basic.lookup.elab]] and [[dcl.type.elab]]. — *end note*]
|
| 186 |
-
|
| 187 |
-
The point of declaration for an injected-class-name [[class.pre]] is
|
| 188 |
immediately following the opening brace of the class definition.
|
| 189 |
|
| 190 |
-
The
|
| 191 |
-
[[dcl.fct.def.general]] is immediately before the
|
| 192 |
-
function definition.
|
| 193 |
|
| 194 |
-
The
|
| 195 |
-
immediately after the *identifier-list* of the structured binding
|
| 196 |
declaration.
|
| 197 |
|
| 198 |
-
The
|
| 199 |
-
declared in the *for-range-declaration* of a range-based `for` statement
|
| 200 |
[[stmt.ranged]] is immediately after the *for-range-initializer*.
|
| 201 |
|
| 202 |
-
The
|
| 203 |
-
its complete *template-parameter*.
|
| 204 |
|
| 205 |
-
[*Example
|
| 206 |
|
| 207 |
``` cpp
|
| 208 |
typedef unsigned char T;
|
| 209 |
template<class T
|
| 210 |
-
= T // lookup finds the typedef
|
| 211 |
, T // lookup finds the template parameter
|
| 212 |
N = 0> struct A { };
|
| 213 |
```
|
| 214 |
|
| 215 |
— *end example*]
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
[*Note 6*: For point of instantiation of a template, see
|
| 226 |
[[temp.point]]. — *end note*]
|
| 227 |
|
| 228 |
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 229 |
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
*handler*
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
statement, any of the outermost blocks) of the controlled statement.
|
| 245 |
|
| 246 |
[*Example 1*:
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
``` cpp
|
| 249 |
if (int x = f()) {
|
| 250 |
int x; // error: redeclaration of x
|
| 251 |
}
|
| 252 |
else {
|
|
@@ -256,314 +381,112 @@ else {
|
|
| 256 |
|
| 257 |
— *end example*]
|
| 258 |
|
| 259 |
### Function parameter scope <a id="basic.scope.param">[[basic.scope.param]]</a>
|
| 260 |
|
| 261 |
-
A
|
| 262 |
-
|
| 263 |
-
parameter scope*. The potential scope of a parameter or function-local
|
| 264 |
-
predefined variable begins at its point of declaration. If the nearest
|
| 265 |
-
enclosing function declarator is not the declarator of a function
|
| 266 |
-
definition, the potential scope ends at the end of that function
|
| 267 |
-
declarator. Otherwise, if the function has a *function-try-block* the
|
| 268 |
-
potential scope ends at the end of the last associated handler.
|
| 269 |
-
Otherwise the potential scope ends at the end of the outermost block of
|
| 270 |
-
the function definition. A parameter name shall not be redeclared in the
|
| 271 |
-
outermost block of the function definition nor in the outermost block of
|
| 272 |
-
any handler associated with a *function-try-block*.
|
| 273 |
|
| 274 |
-
|
|
|
|
| 275 |
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
scope
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
### Namespace scope <a id="basic.scope.namespace">[[basic.scope.namespace]]</a>
|
| 281 |
|
| 282 |
-
|
| 283 |
-
*namespace
|
| 284 |
-
*
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
*using-directive* [[namespace.udir]] that nominates the member’s
|
| 290 |
-
namespace, the member’s potential scope includes that portion of the
|
| 291 |
-
potential scope of the *using-directive* that follows the member’s point
|
| 292 |
-
of declaration.
|
| 293 |
|
| 294 |
[*Example 1*:
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
-
namespace
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
void q();
|
| 302 |
}
|
| 303 |
-
namespace { int l=1; }
|
| 304 |
-
// the potential scope of l is from its point of declaration to the end of the translation unit
|
| 305 |
-
|
| 306 |
-
namespace N {
|
| 307 |
-
int g(char a) { // overloads N::g(int)
|
| 308 |
-
return l+a; // l is from unnamed namespace
|
| 309 |
-
}
|
| 310 |
-
|
| 311 |
-
int i; // error: duplicate definition
|
| 312 |
-
int j(); // OK: duplicate function declaration
|
| 313 |
-
|
| 314 |
-
int j() { // OK: definition of N::j()
|
| 315 |
-
return g(i); // calls N::g(int)
|
| 316 |
-
}
|
| 317 |
-
int q(); // error: different return type
|
| 318 |
}
|
| 319 |
```
|
| 320 |
|
| 321 |
— *end example*]
|
| 322 |
|
| 323 |
-
If a translation unit Q is imported into a translation unit R
|
| 324 |
-
[[module.import]], the potential scope of a name X declared with
|
| 325 |
-
namespace scope in Q is extended to include the portion of the
|
| 326 |
-
corresponding namespace scope in R following the first
|
| 327 |
-
*module-import-declaration* or *module-declaration* in R that imports Q
|
| 328 |
-
(directly or indirectly) if
|
| 329 |
-
|
| 330 |
-
- X does not have internal linkage, and
|
| 331 |
-
- X is declared after the *module-declaration* in Q (if any), and
|
| 332 |
-
- either X is exported or Q and R are part of the same module.
|
| 333 |
-
|
| 334 |
-
[*Note 1*:
|
| 335 |
-
|
| 336 |
-
A *module-import-declaration* imports both the named translation unit(s)
|
| 337 |
-
and any modules named by exported *module-import-declaration*s within
|
| 338 |
-
them, recursively.
|
| 339 |
-
|
| 340 |
-
[*Example 2*:
|
| 341 |
-
|
| 342 |
-
Translation unit #1
|
| 343 |
-
|
| 344 |
-
``` cpp
|
| 345 |
-
export module Q;
|
| 346 |
-
export int sq(int i) { return i*i; }
|
| 347 |
-
```
|
| 348 |
-
|
| 349 |
-
Translation unit #2
|
| 350 |
-
|
| 351 |
-
``` cpp
|
| 352 |
-
export module R;
|
| 353 |
-
export import Q;
|
| 354 |
-
```
|
| 355 |
-
|
| 356 |
-
Translation unit #3
|
| 357 |
-
|
| 358 |
-
``` cpp
|
| 359 |
-
import R;
|
| 360 |
-
int main() { return sq(9); } // OK: sq from module Q
|
| 361 |
-
```
|
| 362 |
-
|
| 363 |
-
— *end example*]
|
| 364 |
-
|
| 365 |
-
— *end note*]
|
| 366 |
-
|
| 367 |
-
A namespace member can also be referred to after the `::` scope
|
| 368 |
-
resolution operator [[expr.prim.id.qual]] applied to the name of its
|
| 369 |
-
namespace or the name of a namespace which nominates the member’s
|
| 370 |
-
namespace in a *using-directive*; see [[namespace.qual]].
|
| 371 |
-
|
| 372 |
-
The outermost declarative region of a translation unit is also a
|
| 373 |
-
namespace, called the *global namespace*. A name declared in the global
|
| 374 |
-
namespace has *global namespace scope* (also called *global scope*). The
|
| 375 |
-
potential scope of such a name begins at its point of declaration
|
| 376 |
-
[[basic.scope.pdecl]] and ends at the end of the translation unit that
|
| 377 |
-
is its declarative region. A name with global namespace scope is said to
|
| 378 |
-
be a *global name*.
|
| 379 |
-
|
| 380 |
### Class scope <a id="basic.scope.class">[[basic.scope.class]]</a>
|
| 381 |
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
-
|
| 387 |
-
its context and when re-evaluated in the completed scope of `S`. No
|
| 388 |
-
diagnostic is required for a violation of this rule.
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
class.
|
| 393 |
-
|
| 394 |
-
The potential scope of a declaration in a class that extends to or past
|
| 395 |
-
the end of a class definition also extends to the regions defined by its
|
| 396 |
-
member definitions, even if the members are defined lexically outside
|
| 397 |
-
the class (this includes static data member definitions, nested class
|
| 398 |
-
definitions, and member function definitions, including the member
|
| 399 |
-
function body and any portion of the declarator part of such definitions
|
| 400 |
-
which follows the *declarator-id*, including a
|
| 401 |
-
*parameter-declaration-clause* and any default arguments
|
| 402 |
-
[[dcl.fct.default]]).
|
| 403 |
|
| 404 |
[*Example 1*:
|
| 405 |
|
| 406 |
``` cpp
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
class X {
|
| 411 |
-
char v[i]; // error: i refers to ::i but when reevaluated is X::i
|
| 412 |
-
int f() { return sizeof(c); } // OK: X::c
|
| 413 |
-
char c;
|
| 414 |
-
enum { i = 2 };
|
| 415 |
-
};
|
| 416 |
-
|
| 417 |
-
typedef char* T;
|
| 418 |
-
struct Y {
|
| 419 |
-
T a; // error: T refers to ::T but when reevaluated is Y::T
|
| 420 |
-
typedef long T;
|
| 421 |
-
T b;
|
| 422 |
};
|
| 423 |
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
typedef I I; // error, even though no reordering involved
|
| 427 |
-
};
|
| 428 |
```
|
| 429 |
|
| 430 |
— *end example*]
|
| 431 |
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
- in the scope of its class (as described above) or a class derived
|
| 435 |
-
[[class.derived]] from its class,
|
| 436 |
-
- after the `.` operator applied to an expression of the type of its
|
| 437 |
-
class [[expr.ref]] or a class derived from its class,
|
| 438 |
-
- after the `->` operator applied to a pointer to an object of its class
|
| 439 |
-
[[expr.ref]] or a class derived from its class,
|
| 440 |
-
- after the `::` scope resolution operator [[expr.prim.id.qual]] applied
|
| 441 |
-
to the name of its class or a class derived from its class.
|
| 442 |
|
| 443 |
### Enumeration scope <a id="basic.scope.enum">[[basic.scope.enum]]</a>
|
| 444 |
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
|
| 449 |
### Template parameter scope <a id="basic.scope.temp">[[basic.scope.temp]]</a>
|
| 450 |
|
| 451 |
-
|
| 452 |
-
*template
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
[*
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
namespace N {
|
| 467 |
-
template<class T> struct A { }; // #1
|
| 468 |
-
template<class U> void f(U) { } // #2
|
| 469 |
-
struct B {
|
| 470 |
-
template<class V> friend int g(struct C*); // #3
|
| 471 |
-
};
|
| 472 |
-
}
|
| 473 |
-
```
|
| 474 |
-
|
| 475 |
-
The declarative regions of `T`, `U` and `V` are the
|
| 476 |
-
*template-declaration*s on lines \#1, \#2, and \#3, respectively. But
|
| 477 |
-
the names `A`, `f`, `g` and `C` all belong to the same declarative
|
| 478 |
-
region — namely, the *namespace-body* of `N`. (`g` is still considered
|
| 479 |
-
to belong to this declarative region in spite of its being hidden during
|
| 480 |
-
qualified and unqualified name lookup.)
|
| 481 |
-
|
| 482 |
-
— *end example*]
|
| 483 |
-
|
| 484 |
-
The potential scope of a template parameter name begins at its point of
|
| 485 |
-
declaration [[basic.scope.pdecl]] and ends at the end of its declarative
|
| 486 |
-
region.
|
| 487 |
-
|
| 488 |
-
[*Note 1*:
|
| 489 |
-
|
| 490 |
-
This implies that a *template-parameter* can be used in the declaration
|
| 491 |
-
of subsequent *template-parameter*s and their default arguments but
|
| 492 |
-
cannot be used in preceding *template-parameter*s or their default
|
| 493 |
-
arguments. For example,
|
| 494 |
-
|
| 495 |
-
``` cpp
|
| 496 |
-
template<class T, T* p, class U = T> class X { ... };
|
| 497 |
-
template<class T> void f(T* p = new T);
|
| 498 |
-
```
|
| 499 |
-
|
| 500 |
-
This also implies that a *template-parameter* can be used in the
|
| 501 |
-
specification of base classes. For example,
|
| 502 |
-
|
| 503 |
-
``` cpp
|
| 504 |
-
template<class T> class X : public Array<T> { ... };
|
| 505 |
-
template<class T> class Y : public T { ... };
|
| 506 |
-
```
|
| 507 |
-
|
| 508 |
-
The use of a template parameter as a base class implies that a class
|
| 509 |
-
used as a template argument must be defined and not just declared when
|
| 510 |
-
the class template is instantiated.
|
| 511 |
-
|
| 512 |
-
— *end note*]
|
| 513 |
-
|
| 514 |
-
The declarative region of the name of a template parameter is nested
|
| 515 |
-
within the immediately-enclosing declarative region.
|
| 516 |
-
|
| 517 |
-
[*Note 2*:
|
| 518 |
-
|
| 519 |
-
As a result, a *template-parameter* hides any entity with the same name
|
| 520 |
-
in an enclosing scope [[basic.scope.hiding]].
|
| 521 |
-
|
| 522 |
-
[*Example 2*:
|
| 523 |
-
|
| 524 |
-
``` cpp
|
| 525 |
-
typedef int N;
|
| 526 |
-
template<N X, typename N, template<N Y> class T> struct A;
|
| 527 |
-
```
|
| 528 |
-
|
| 529 |
-
Here, `X` is a non-type template parameter of type `int` and `Y` is a
|
| 530 |
-
non-type template parameter of the same type as the second template
|
| 531 |
-
parameter of `A`.
|
| 532 |
-
|
| 533 |
-
— *end example*]
|
| 534 |
-
|
| 535 |
-
— *end note*]
|
| 536 |
-
|
| 537 |
-
[*Note 3*: Because the name of a template parameter cannot be
|
| 538 |
-
redeclared within its potential scope [[temp.local]], a template
|
| 539 |
-
parameter’s scope is often its potential scope. However, it is still
|
| 540 |
-
possible for a template parameter name to be hidden; see
|
| 541 |
-
[[temp.local]]. — *end note*]
|
| 542 |
-
|
| 543 |
-
### Name hiding <a id="basic.scope.hiding">[[basic.scope.hiding]]</a>
|
| 544 |
-
|
| 545 |
-
A declaration of a name in a nested declarative region hides a
|
| 546 |
-
declaration of the same name in an enclosing declarative region; see
|
| 547 |
-
[[basic.scope.declarative]] and [[basic.lookup.unqual]].
|
| 548 |
-
|
| 549 |
-
If a class name [[class.name]] or enumeration name [[dcl.enum]] and a
|
| 550 |
-
variable, data member, function, or enumerator are declared in the same
|
| 551 |
-
declarative region (in any order) with the same name (excluding
|
| 552 |
-
declarations made visible via *using-directive*s
|
| 553 |
-
[[basic.lookup.unqual]]), the class or enumeration name is hidden
|
| 554 |
-
wherever the variable, data member, function, or enumerator name is
|
| 555 |
-
visible.
|
| 556 |
-
|
| 557 |
-
In a member function definition, the declaration of a name at block
|
| 558 |
-
scope hides the declaration of a member of the class with the same name;
|
| 559 |
-
see [[basic.scope.class]]. The declaration of a member in a derived
|
| 560 |
-
class [[class.derived]] hides the declaration of a member of a base
|
| 561 |
-
class of the same name; see [[class.member.lookup]].
|
| 562 |
-
|
| 563 |
-
During the lookup of a name qualified by a namespace name, declarations
|
| 564 |
-
that would otherwise be made visible by a *using-directive* can be
|
| 565 |
-
hidden by declarations with the same name in the namespace containing
|
| 566 |
-
the *using-directive*; see [[namespace.qual]].
|
| 567 |
-
|
| 568 |
-
If a name is in scope and is not hidden it is said to be *visible*.
|
| 569 |
|
|
|
|
| 1 |
## Scope <a id="basic.scope">[[basic.scope]]</a>
|
| 2 |
|
| 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*, or *handler* (as described
|
| 9 |
+
in the following subclauses of [[basic.scope]]) appearing in another
|
| 10 |
+
scope which thereby contains S. An *enclosing scope* at a program point
|
| 11 |
+
is any scope that contains it; the smallest such scope is said to be the
|
| 12 |
+
*immediate scope* at that point. A scope *intervenes* between a program
|
| 13 |
+
point P and a scope S (that does not contain P) if it is or contains S
|
| 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.
|
| 20 |
+
- A declaration *inhabits* the immediate scope at its locus
|
| 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 |
+
An entity *belongs* to a scope S if S is the target scope of a
|
| 27 |
+
declaration of the entity.
|
| 28 |
+
|
| 29 |
+
[*Note 1*:
|
| 30 |
+
|
| 31 |
+
Special cases include that:
|
| 32 |
+
|
| 33 |
+
- Template parameter scopes are parents only to other template parameter
|
| 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 qualified names and template
|
| 40 |
+
specializations do not bind names [[dcl.meaning]]; those with
|
| 41 |
+
qualified names target a specified scope, and other friend
|
| 42 |
+
declarations and certain *elaborated-type-specifier*s
|
| 43 |
+
[[dcl.type.elab]] target a larger enclosing scope.
|
| 44 |
+
- Block-scope extern declarations target a larger enclosing scope but
|
| 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 top-level 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.
|
| 69 |
+
|
| 70 |
+
Two function templates have *corresponding signatures* if their
|
| 71 |
+
*template-parameter-list*s have the same length, their corresponding
|
| 72 |
+
*template-parameter*s are equivalent, they have equivalent
|
| 73 |
+
non-object-parameter-type-lists and return types (if any), and, if both
|
| 74 |
+
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 *typedef-name*) 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, except when
|
| 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 |
+
equivalent *template-head*s and trailing *requires-clause*s (if
|
| 91 |
+
any).
|
| 92 |
+
|
| 93 |
+
[*Note 2*:
|
| 94 |
+
|
| 95 |
+
Declarations can correspond even if neither binds a name.
|
| 96 |
|
| 97 |
[*Example 1*:
|
| 98 |
|
| 99 |
+
``` cpp
|
| 100 |
+
struct A {
|
| 101 |
+
friend void f(); // #1
|
| 102 |
+
};
|
| 103 |
+
struct B {
|
| 104 |
+
friend void f() {} // corresponds to, and defines, #1
|
| 105 |
+
};
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
— *end example*]
|
| 109 |
+
|
| 110 |
+
— *end note*]
|
| 111 |
+
|
| 112 |
+
[*Example 2*:
|
| 113 |
|
| 114 |
``` cpp
|
| 115 |
+
typedef int Int;
|
| 116 |
+
enum E : int { a };
|
| 117 |
+
void f(int); // #1
|
| 118 |
+
void f(Int) {} // defines #1
|
| 119 |
+
void f(E) {} // OK, another overload
|
| 120 |
+
|
| 121 |
+
struct X {
|
| 122 |
+
static void f();
|
| 123 |
+
void f() const; // error: redeclaration
|
| 124 |
+
void g();
|
| 125 |
+
void g() const; // OK
|
| 126 |
+
void g() &; // error: redeclaration
|
| 127 |
+
|
| 128 |
+
void h(this X&, int);
|
| 129 |
+
void h(int) &&; // OK, another overload
|
| 130 |
+
void j(this const X&);
|
| 131 |
+
void j() const &; // error: redeclaration
|
| 132 |
+
void k();
|
| 133 |
+
void k(this X&); // error: redeclaration
|
| 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 one precedes the other
|
| 143 |
+
[[basic.lookup]].
|
| 144 |
+
|
| 145 |
+
[*Note 3*: Overload resolution can consider potentially conflicting
|
| 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*:
|
| 151 |
+
|
| 152 |
+
``` cpp
|
| 153 |
+
void f() {
|
| 154 |
+
int x,y;
|
| 155 |
+
void x(); // error: different entity for x
|
| 156 |
+
int y; // error: redefinition
|
| 157 |
+
}
|
| 158 |
+
enum { f }; // error: different entity for ::f
|
| 159 |
+
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
|
| 170 |
+
at a point P if it precedes P, it does not inhabit a block scope, and
|
| 171 |
+
its target scope is the scope associated with E or, if E is a namespace,
|
| 172 |
+
any element of the inline namespace set of E [[namespace.def]].
|
| 173 |
+
|
| 174 |
+
[*Example 4*:
|
| 175 |
+
|
| 176 |
+
``` cpp
|
| 177 |
+
namespace A {
|
| 178 |
+
void f() {void g();}
|
| 179 |
+
inline namespace B {
|
| 180 |
+
struct S {
|
| 181 |
+
friend void h();
|
| 182 |
+
static int i;
|
| 183 |
+
};
|
| 184 |
+
}
|
| 185 |
}
|
| 186 |
```
|
| 187 |
|
| 188 |
+
At the end of this example, the declarations of `f`, `B`, `S`, and `h`
|
| 189 |
+
are nominable in `A`, but those of `g` and `i` are not.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
— *end example*]
|
| 192 |
|
| 193 |
+
When instantiating a templated entity [[temp.pre]], any scope S
|
| 194 |
+
introduced by any part of the template definition is considered to be
|
| 195 |
+
introduced by the instantiated entity and to contain the instantiations
|
| 196 |
+
of any declarations that inhabit S.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
### Point of declaration <a id="basic.scope.pdecl">[[basic.scope.pdecl]]</a>
|
| 199 |
|
| 200 |
+
The *locus* of a declaration [[basic.pre]] that is a declarator is
|
| 201 |
+
immediately after the complete declarator [[dcl.decl]].
|
|
|
|
| 202 |
|
| 203 |
[*Example 1*:
|
| 204 |
|
| 205 |
``` cpp
|
| 206 |
unsigned char x = 12;
|
|
|
|
| 213 |
|
| 214 |
— *end example*]
|
| 215 |
|
| 216 |
[*Note 1*:
|
| 217 |
|
| 218 |
+
A name from an outer scope remains visible up to the locus of the
|
| 219 |
+
declaration that hides it.
|
| 220 |
|
| 221 |
[*Example 2*:
|
| 222 |
|
| 223 |
``` cpp
|
| 224 |
const int i = 2;
|
|
|
|
| 229 |
|
| 230 |
— *end example*]
|
| 231 |
|
| 232 |
— *end note*]
|
| 233 |
|
| 234 |
+
The locus of a *class-specifier* is immediately after the *identifier*
|
| 235 |
+
or *simple-template-id* (if any) in its *class-head* [[class.pre]]. The
|
| 236 |
+
locus of an *enum-specifier* is immediately after its *enum-head*; the
|
| 237 |
+
locus of an *opaque-enum-declaration* is immediately after it
|
| 238 |
+
[[dcl.enum]]. The locus of an *alias-declaration* is immediately after
|
| 239 |
+
it.
|
|
|
|
|
|
|
| 240 |
|
| 241 |
+
The locus of a *using-declarator* that does not name a constructor is
|
| 242 |
+
immediately after the *using-declarator* [[namespace.udecl]].
|
|
|
|
| 243 |
|
| 244 |
+
The locus of an *enumerator-definition* is immediately after it.
|
|
|
|
| 245 |
|
| 246 |
[*Example 3*:
|
| 247 |
|
| 248 |
``` cpp
|
| 249 |
const int x = 12;
|
|
|
|
| 253 |
Here, the enumerator `x` is initialized with the value of the constant
|
| 254 |
`x`, namely 12.
|
| 255 |
|
| 256 |
— *end example*]
|
| 257 |
|
|
|
|
|
|
|
|
|
|
| 258 |
[*Note 2*:
|
| 259 |
|
| 260 |
+
After the declaration of a class member, the member name can be found in
|
| 261 |
+
the scope of its class even if the class is an incomplete class.
|
| 262 |
+
|
| 263 |
+
[*Example 4*:
|
| 264 |
|
| 265 |
``` cpp
|
| 266 |
struct X {
|
| 267 |
enum E { z = 16 };
|
| 268 |
int b[X::z]; // OK
|
| 269 |
};
|
| 270 |
```
|
| 271 |
|
| 272 |
+
— *end example*]
|
| 273 |
+
|
| 274 |
— *end note*]
|
| 275 |
|
| 276 |
+
The locus of an *elaborated-type-specifier* that is a declaration
|
| 277 |
+
[[dcl.type.elab]] is immediately after it.
|
| 278 |
|
| 279 |
+
The locus of an injected-class-name declaration [[class.pre]] is
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
immediately following the opening brace of the class definition.
|
| 281 |
|
| 282 |
+
The locus of the implicit declaration of a function-local predefined
|
| 283 |
+
variable [[dcl.fct.def.general]] is immediately before the
|
| 284 |
+
*function-body* of its function’s definition.
|
| 285 |
|
| 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 |
|
| 297 |
``` cpp
|
| 298 |
typedef unsigned char T;
|
| 299 |
template<class T
|
| 300 |
+
= T // lookup finds the typedef-name
|
| 301 |
, T // lookup finds the template parameter
|
| 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
|
| 314 |
+
immediately after the *identifier*.
|
| 315 |
+
|
| 316 |
+
[*Note 4*: An identifier is invented for an
|
| 317 |
+
*unnamed-namespace-definition* [[namespace.unnamed]]. — *end note*]
|
| 318 |
+
|
| 319 |
+
[*Note 5*: Friend declarations can introduce functions or classes that
|
| 320 |
+
belong to the nearest enclosing namespace or block scope, but they do
|
| 321 |
+
not bind names anywhere [[class.friend]]. Function declarations at block
|
| 322 |
+
scope and variable declarations with the `extern` specifier at block
|
| 323 |
+
scope declare entities that belong to the nearest enclosing namespace,
|
| 324 |
+
but they do not bind names in it. — *end note*]
|
| 325 |
|
| 326 |
[*Note 6*: For point of instantiation of a template, see
|
| 327 |
[[temp.point]]. — *end note*]
|
| 328 |
|
| 329 |
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 330 |
|
| 331 |
+
Each
|
| 332 |
+
|
| 333 |
+
- selection or iteration statement [[stmt.select]], [[stmt.iter]],
|
| 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 |
+
|
| 339 |
+
introduces a *block scope* that includes that statement or *handler*.
|
| 340 |
+
|
| 341 |
+
[*Note 1*: A substatement that is also a block has only one
|
| 342 |
+
scope. — *end note*]
|
| 343 |
+
|
| 344 |
+
A variable that belongs to a block scope is a *block variable*.
|
|
|
|
| 345 |
|
| 346 |
[*Example 1*:
|
| 347 |
|
| 348 |
+
``` cpp
|
| 349 |
+
int i = 42;
|
| 350 |
+
int a[10];
|
| 351 |
+
|
| 352 |
+
for (int i = 0; i < 10; i++)
|
| 353 |
+
a[i] = i;
|
| 354 |
+
|
| 355 |
+
int j = i; // j = 42
|
| 356 |
+
```
|
| 357 |
+
|
| 358 |
+
— *end example*]
|
| 359 |
+
|
| 360 |
+
If a declaration whose target scope is the block scope S of a
|
| 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
|
| 366 |
+
- *handler* of a *function-try-block*
|
| 367 |
+
|
| 368 |
+
potentially conflicts with a declaration whose target scope is the
|
| 369 |
+
parent scope of S, the program is ill-formed.
|
| 370 |
+
|
| 371 |
+
[*Example 2*:
|
| 372 |
+
|
| 373 |
``` cpp
|
| 374 |
if (int x = f()) {
|
| 375 |
int x; // error: redeclaration of x
|
| 376 |
}
|
| 377 |
else {
|
|
|
|
| 381 |
|
| 382 |
— *end example*]
|
| 383 |
|
| 384 |
### Function parameter scope <a id="basic.scope.param">[[basic.scope.param]]</a>
|
| 385 |
|
| 386 |
+
A *parameter-declaration-clause* P introduces a
|
| 387 |
+
*function parameter scope* that includes P.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
+
[*Note 1*: A function parameter cannot be used for its value within the
|
| 390 |
+
*parameter-declaration-clause* [[dcl.fct.default]]. — *end note*]
|
| 391 |
|
| 392 |
+
- If P is associated with a *declarator* and is preceded by a
|
| 393 |
+
(possibly-parenthesized) *noptr-declarator* of the form
|
| 394 |
+
*declarator-id* *attribute-specifier-seq*ₒₚₜ , its scope extends to
|
| 395 |
+
the end of the nearest enclosing *init-declarator*,
|
| 396 |
+
*member-declarator*, *declarator* of a *parameter-declaration* or a
|
| 397 |
+
*nodeclspec-function-declaration*, or *function-definition*, but does
|
| 398 |
+
not include the locus of the associated *declarator*. \[*Note 2*: In
|
| 399 |
+
this case, P declares the parameters of a function (or a function or
|
| 400 |
+
template parameter declared with function type). A member function’s
|
| 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 |
+
|
| 412 |
+
A *lambda-expression* `E` introduces a *lambda scope* that starts
|
| 413 |
+
immediately after the *lambda-introducer* of `E` and extends to the end
|
| 414 |
+
of the *compound-statement* of `E`.
|
| 415 |
|
| 416 |
### Namespace scope <a id="basic.scope.namespace">[[basic.scope.namespace]]</a>
|
| 417 |
|
| 418 |
+
Any *namespace-definition* for a namespace N introduces a
|
| 419 |
+
*namespace scope* that includes the *namespace-body* for every
|
| 420 |
+
*namespace-definition* for N. For each non-friend redeclaration or
|
| 421 |
+
specialization whose target scope is or is contained by the scope, the
|
| 422 |
+
portion after the *declarator-id*, *class-head-name*, or
|
| 423 |
+
*enum-head-name* is also included in the scope. The global scope is the
|
| 424 |
+
namespace scope of the global namespace [[basic.namespace]].
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
|
| 426 |
[*Example 1*:
|
| 427 |
|
| 428 |
``` cpp
|
| 429 |
+
namespace Q {
|
| 430 |
+
namespace V { void f(); }
|
| 431 |
+
void V::f() { // in the scope of V
|
| 432 |
+
void h(); // declares Q::V::h
|
|
|
|
| 433 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
}
|
| 435 |
```
|
| 436 |
|
| 437 |
— *end example*]
|
| 438 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
### Class scope <a id="basic.scope.class">[[basic.scope.class]]</a>
|
| 440 |
|
| 441 |
+
Any declaration of a class or class template C introduces a
|
| 442 |
+
*class scope* that includes the *member-specification* of the
|
| 443 |
+
*class-specifier* for C (if any). For each non-friend redeclaration or
|
| 444 |
+
specialization whose target scope is or is contained by the scope, the
|
| 445 |
+
portion after the *declarator-id*, *class-head-name*, or
|
| 446 |
+
*enum-head-name* is also included in the scope.
|
| 447 |
|
| 448 |
+
[*Note 1*:
|
|
|
|
|
|
|
| 449 |
|
| 450 |
+
Lookup from a program point before the *class-specifier* of a class will
|
| 451 |
+
find no bindings in the class scope.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
[*Example 1*:
|
| 454 |
|
| 455 |
``` cpp
|
| 456 |
+
template<class D>
|
| 457 |
+
struct B {
|
| 458 |
+
D::type x; // #1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
};
|
| 460 |
|
| 461 |
+
struct A { using type = int; };
|
| 462 |
+
struct C : A, B<C> {}; // error at #1: C::type not found
|
|
|
|
|
|
|
| 463 |
```
|
| 464 |
|
| 465 |
— *end example*]
|
| 466 |
|
| 467 |
+
— *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
|
| 469 |
### Enumeration scope <a id="basic.scope.enum">[[basic.scope.enum]]</a>
|
| 470 |
|
| 471 |
+
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 template *template-parameter* introduces a
|
| 478 |
+
*template parameter scope* that includes the *template-head* of the
|
| 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
|
| 485 |
+
the same scope as D. The parent scope of any scope S that is not a
|
| 486 |
+
template parameter scope is the smallest scope that contains S and is
|
| 487 |
+
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 |
|