- tmp/tmp45tv0toy/{from.md → to.md} +94 -280
tmp/tmp45tv0toy/{from.md → to.md}
RENAMED
|
@@ -1,301 +1,115 @@
|
|
| 1 |
### Unqualified name lookup <a id="basic.lookup.unqual">[[basic.lookup.unqual]]</a>
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
namespace nominated by
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
The rules in [[basic.lookup.argdep]] have no effect on the syntactic
|
| 42 |
-
interpretation of an expression. For example,
|
| 43 |
-
|
| 44 |
-
``` cpp
|
| 45 |
-
typedef int f;
|
| 46 |
-
namespace N {
|
| 47 |
-
struct A {
|
| 48 |
-
friend void f(A &);
|
| 49 |
-
operator int();
|
| 50 |
-
void g(A a) {
|
| 51 |
-
int i = f(a); // f is the typedef, not the friend function: equivalent to int(a)
|
| 52 |
-
}
|
| 53 |
-
};
|
| 54 |
-
}
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
-
Because the expression is not a function call, the argument-dependent
|
| 58 |
-
name lookup [[basic.lookup.argdep]] does not apply and the friend
|
| 59 |
-
function `f` is not found.
|
| 60 |
-
|
| 61 |
-
— *end note*]
|
| 62 |
-
|
| 63 |
-
A name used in global scope, outside of any function, class or
|
| 64 |
-
user-declared namespace, shall be declared before its use in global
|
| 65 |
-
scope.
|
| 66 |
-
|
| 67 |
-
A name used in a user-declared namespace outside of the definition of
|
| 68 |
-
any function or class shall be declared before its use in that namespace
|
| 69 |
-
or before its use in a namespace enclosing its namespace.
|
| 70 |
-
|
| 71 |
-
In the definition of a function that is a member of namespace `N`, a
|
| 72 |
-
name used after the function’s *declarator-id*[^3] shall be declared
|
| 73 |
-
before its use in the block in which it is used or in one of its
|
| 74 |
-
enclosing blocks [[stmt.block]] or shall be declared before its use in
|
| 75 |
-
namespace `N` or, if `N` is a nested namespace, shall be declared before
|
| 76 |
-
its use in one of `N`’s enclosing namespaces.
|
| 77 |
|
| 78 |
[*Example 1*:
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
}
|
| 86 |
-
void A::N::f() {
|
| 87 |
-
i = 5;
|
| 88 |
-
// The following scopes are searched for a declaration of i:
|
| 89 |
-
// 1) outermost block scope of A::N::f, before the use of i
|
| 90 |
-
// 2) scope of namespace N
|
| 91 |
-
// 3) scope of namespace A
|
| 92 |
-
// 4) global scope, before the definition of A::N::f
|
| 93 |
-
}
|
| 94 |
-
```
|
| 95 |
|
| 96 |
-
— *end example*]
|
| 97 |
-
|
| 98 |
-
A name used in the definition of a class `X` [^4] outside of a
|
| 99 |
-
complete-class context [[class.mem]] of `X` shall be declared in one of
|
| 100 |
-
the following ways:
|
| 101 |
-
|
| 102 |
-
- before its use in class `X` or be a member of a base class of `X`
|
| 103 |
-
[[class.member.lookup]], or
|
| 104 |
-
- if `X` is a nested class of class `Y` [[class.nest]], before the
|
| 105 |
-
definition of `X` in `Y`, or shall be a member of a base class of `Y`
|
| 106 |
-
(this lookup applies in turn to `Y`’s enclosing classes, starting with
|
| 107 |
-
the innermost enclosing class),[^5] or
|
| 108 |
-
- if `X` is a local class [[class.local]] or is a nested class of a
|
| 109 |
-
local class, before the definition of class `X` in a block enclosing
|
| 110 |
-
the definition of class `X`, or
|
| 111 |
-
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 112 |
-
that is a member of `N`, or is a local class or a nested class within
|
| 113 |
-
a local class of a function that is a member of `N`, before the
|
| 114 |
-
definition of class `X` in namespace `N` or in one of `N`’s enclosing
|
| 115 |
-
namespaces.
|
| 116 |
-
|
| 117 |
-
[*Example 2*:
|
| 118 |
-
|
| 119 |
-
``` cpp
|
| 120 |
-
namespace M {
|
| 121 |
-
class B { };
|
| 122 |
-
}
|
| 123 |
-
```
|
| 124 |
-
|
| 125 |
-
``` cpp
|
| 126 |
-
namespace N {
|
| 127 |
-
class Y : public M::B {
|
| 128 |
-
class X {
|
| 129 |
-
int a[i];
|
| 130 |
-
};
|
| 131 |
-
};
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
// The following scopes are searched for a declaration of i:
|
| 135 |
-
// 1) scope of class N::Y::X, before the use of i
|
| 136 |
-
// 2) scope of class N::Y, before the definition of N::Y::X
|
| 137 |
-
// 3) scope of N::Y's base class M::B
|
| 138 |
-
// 4) scope of namespace N, before the definition of N::Y
|
| 139 |
-
// 5) global scope, before the definition of N
|
| 140 |
-
```
|
| 141 |
-
|
| 142 |
-
— *end example*]
|
| 143 |
-
|
| 144 |
-
[*Note 2*: When looking for a prior declaration of a class or function
|
| 145 |
-
introduced by a friend declaration, scopes outside of the innermost
|
| 146 |
-
enclosing namespace scope are not considered; see
|
| 147 |
-
[[namespace.memdef]]. — *end note*]
|
| 148 |
-
|
| 149 |
-
[*Note 3*: [[basic.scope.class]] further describes the restrictions on
|
| 150 |
-
the use of names in a class definition. [[class.nest]] further describes
|
| 151 |
-
the restrictions on the use of names in nested class definitions.
|
| 152 |
-
[[class.local]] further describes the restrictions on the use of names
|
| 153 |
-
in local class definitions. — *end note*]
|
| 154 |
-
|
| 155 |
-
For the members of a class `X`, a name used in a complete-class context
|
| 156 |
-
[[class.mem]] of `X` or in the definition of a class member outside of
|
| 157 |
-
the definition of `X`, following the member’s *declarator-id*[^6], shall
|
| 158 |
-
be declared in one of the following ways:
|
| 159 |
-
|
| 160 |
-
- before its use in the block in which it is used or in an enclosing
|
| 161 |
-
block [[stmt.block]], or
|
| 162 |
-
- shall be a member of class `X` or be a member of a base class of `X`
|
| 163 |
-
[[class.member.lookup]], or
|
| 164 |
-
- if `X` is a nested class of class `Y` [[class.nest]], shall be a
|
| 165 |
-
member of `Y`, or shall be a member of a base class of `Y` (this
|
| 166 |
-
lookup applies in turn to `Y`’s enclosing classes, starting with the
|
| 167 |
-
innermost enclosing class),[^7] or
|
| 168 |
-
- if `X` is a local class [[class.local]] or is a nested class of a
|
| 169 |
-
local class, before the definition of class `X` in a block enclosing
|
| 170 |
-
the definition of class `X`, or
|
| 171 |
-
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 172 |
-
that is a member of `N`, or is a local class or a nested class within
|
| 173 |
-
a local class of a function that is a member of `N`, before the use of
|
| 174 |
-
the name, in namespace `N` or in one of `N`’s enclosing namespaces.
|
| 175 |
-
|
| 176 |
-
[*Example 3*:
|
| 177 |
-
|
| 178 |
-
``` cpp
|
| 179 |
-
class B { };
|
| 180 |
-
namespace M {
|
| 181 |
-
namespace N {
|
| 182 |
-
class X : public B {
|
| 183 |
-
void f();
|
| 184 |
-
};
|
| 185 |
-
}
|
| 186 |
-
}
|
| 187 |
-
void M::N::X::f() {
|
| 188 |
-
i = 16;
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
// The following scopes are searched for a declaration of i:
|
| 192 |
-
// 1) outermost block scope of M::N::X::f, before the use of i
|
| 193 |
-
// 2) scope of class M::N::X
|
| 194 |
-
// 3) scope of M::N::X's base class B
|
| 195 |
-
// 4) scope of namespace M::N
|
| 196 |
-
// 5) scope of namespace M
|
| 197 |
-
// 6) global scope, before the definition of M::N::X::f
|
| 198 |
-
```
|
| 199 |
-
|
| 200 |
-
— *end example*]
|
| 201 |
-
|
| 202 |
-
[*Note 4*: [[class.mfct]] and [[class.static]] further describe the
|
| 203 |
-
restrictions on the use of names in member function definitions.
|
| 204 |
-
[[class.nest]] further describes the restrictions on the use of names in
|
| 205 |
-
the scope of nested classes. [[class.local]] further describes the
|
| 206 |
-
restrictions on the use of names in local class
|
| 207 |
-
definitions. — *end note*]
|
| 208 |
-
|
| 209 |
-
Name lookup for a name used in the definition of a friend function
|
| 210 |
-
[[class.friend]] defined inline in the class granting friendship shall
|
| 211 |
-
proceed as described for lookup in member function definitions. If the
|
| 212 |
-
friend function is not defined in the class granting friendship, name
|
| 213 |
-
lookup in the friend function definition shall proceed as described for
|
| 214 |
-
lookup in namespace member function definitions.
|
| 215 |
-
|
| 216 |
-
In a friend declaration naming a member function, a name used in the
|
| 217 |
-
function declarator and not part of a *template-argument* in the
|
| 218 |
-
*declarator-id* is first looked up in the scope of the member function’s
|
| 219 |
-
class [[class.member.lookup]]. If it is not found, or if the name is
|
| 220 |
-
part of a *template-argument* in the *declarator-id*, the look up is as
|
| 221 |
-
described for unqualified names in the definition of the class granting
|
| 222 |
-
friendship.
|
| 223 |
-
|
| 224 |
-
[*Example 4*:
|
| 225 |
-
|
| 226 |
-
``` cpp
|
| 227 |
-
struct A {
|
| 228 |
-
typedef int AT;
|
| 229 |
-
void f1(AT);
|
| 230 |
-
void f2(float);
|
| 231 |
-
template <class T> void f3();
|
| 232 |
-
};
|
| 233 |
struct B {
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
|
|
|
| 239 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
```
|
| 241 |
|
| 242 |
— *end example*]
|
| 243 |
|
| 244 |
-
|
| 245 |
-
[[
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
containing the function declaration.
|
| 250 |
|
| 251 |
-
[*
|
| 252 |
-
the use of names in default arguments. [[class.base.init]] further
|
| 253 |
-
describes the restrictions on the use of names in a
|
| 254 |
-
*ctor-initializer*. — *end note*]
|
| 255 |
-
|
| 256 |
-
During the lookup of a name used in the *constant-expression* of an
|
| 257 |
-
*enumerator-definition*, previously declared *enumerator*s of the
|
| 258 |
-
enumeration are visible and hide the names of entities declared in the
|
| 259 |
-
block, class, or namespace scopes containing the *enum-specifier*.
|
| 260 |
-
|
| 261 |
-
A name used in the definition of a `static` data member of class `X`
|
| 262 |
-
[[class.static.data]] (after the *qualified-id* of the static member) is
|
| 263 |
-
looked up as if the name was used in a member function of `X`.
|
| 264 |
-
|
| 265 |
-
[*Note 6*: [[class.static.data]] further describes the restrictions on
|
| 266 |
-
the use of names in the definition of a `static` data
|
| 267 |
-
member. — *end note*]
|
| 268 |
-
|
| 269 |
-
If a variable member of a namespace is defined outside of the scope of
|
| 270 |
-
its namespace then any name that appears in the definition of the member
|
| 271 |
-
(after the *declarator-id*) is looked up as if the definition of the
|
| 272 |
-
member occurred in its namespace.
|
| 273 |
-
|
| 274 |
-
[*Example 5*:
|
| 275 |
|
| 276 |
``` cpp
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
}
|
| 281 |
-
|
| 282 |
-
int i = 2;
|
| 283 |
-
|
| 284 |
-
int N::j = i; // N::j == 4
|
| 285 |
```
|
| 286 |
|
| 287 |
— *end example*]
|
| 288 |
|
| 289 |
-
A name used in the handler for a *function-try-block* [[except.pre]] is
|
| 290 |
-
looked up as if the name was used in the outermost block of the function
|
| 291 |
-
definition. In particular, the function parameter names shall not be
|
| 292 |
-
redeclared in the *exception-declaration* nor in the outermost block of
|
| 293 |
-
a handler for the *function-try-block*. Names declared in the outermost
|
| 294 |
-
block of the function definition are not found when looked up in the
|
| 295 |
-
scope of a handler for the *function-try-block*.
|
| 296 |
-
|
| 297 |
-
[*Note 7*: But function parameter names are found. — *end note*]
|
| 298 |
-
|
| 299 |
-
[*Note 8*: The rules for name lookup in template definitions are
|
| 300 |
-
described in [[temp.res]]. — *end note*]
|
| 301 |
-
|
|
|
|
| 1 |
### Unqualified name lookup <a id="basic.lookup.unqual">[[basic.lookup.unqual]]</a>
|
| 2 |
|
| 3 |
+
A *using-directive* is *active* in a scope S at a program point P if it
|
| 4 |
+
precedes P and inhabits either S or the scope of a namespace nominated
|
| 5 |
+
by a *using-directive* that is active in S at P.
|
| 6 |
+
|
| 7 |
+
An *unqualified search* in a scope S from a program point P includes the
|
| 8 |
+
results of searches from P in
|
| 9 |
+
|
| 10 |
+
- S, and
|
| 11 |
+
- for any scope U that contains P and is or is contained by S, each
|
| 12 |
+
namespace contained by S that is nominated by a *using-directive* that
|
| 13 |
+
is active in U at P.
|
| 14 |
+
|
| 15 |
+
If no declarations are found, the results of the unqualified search are
|
| 16 |
+
the results of an unqualified search in the parent scope of S, if any,
|
| 17 |
+
from P.
|
| 18 |
+
|
| 19 |
+
[*Note 1*: When a class scope is searched, the scopes of its base
|
| 20 |
+
classes are also searched [[class.member.lookup]]. If it inherits from a
|
| 21 |
+
single base, it is as if the scope of the base immediately contains the
|
| 22 |
+
scope of the derived class. Template parameter scopes that are
|
| 23 |
+
associated with one scope in the chain of parents are also considered
|
| 24 |
+
[[temp.local]]. — *end note*]
|
| 25 |
+
|
| 26 |
+
*Unqualified name lookup* from a program point performs an unqualified
|
| 27 |
+
search in its immediate scope.
|
| 28 |
+
|
| 29 |
+
An *unqualified name* is a name that does not immediately follow a
|
| 30 |
+
*nested-name-specifier* or the `.` or `->` in a class member access
|
| 31 |
+
expression [[expr.ref]], possibly after a `template` keyword or `~`.
|
| 32 |
+
Unless otherwise specified, such a name undergoes unqualified name
|
| 33 |
+
lookup from the point where it appears.
|
| 34 |
+
|
| 35 |
+
An unqualified name that is a component name [[expr.prim.id.unqual]] of
|
| 36 |
+
a *type-specifier* or *ptr-operator* of a *conversion-type-id* is looked
|
| 37 |
+
up in the same fashion as the *conversion-function-id* in which it
|
| 38 |
+
appears. If that lookup finds nothing, it undergoes unqualified name
|
| 39 |
+
lookup; in each case, only names that denote types or templates whose
|
| 40 |
+
specializations are types are considered.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
[*Example 1*:
|
| 43 |
|
| 44 |
``` cpp
|
| 45 |
+
struct T1 { struct U { int i; }; };
|
| 46 |
+
struct T2 { };
|
| 47 |
+
struct U1 {};
|
| 48 |
+
struct U2 {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
struct B {
|
| 51 |
+
using T = T1;
|
| 52 |
+
using U = U1;
|
| 53 |
+
operator U1 T1::*();
|
| 54 |
+
operator U1 T2::*();
|
| 55 |
+
operator U2 T1::*();
|
| 56 |
+
operator U2 T2::*();
|
| 57 |
};
|
| 58 |
+
|
| 59 |
+
template<class X, class T>
|
| 60 |
+
int g() {
|
| 61 |
+
using U = U2;
|
| 62 |
+
X().operator U T::*(); // #1, searches for T in the scope of X first
|
| 63 |
+
X().operator U decltype(T())::*(); // #2
|
| 64 |
+
return 0;
|
| 65 |
+
}
|
| 66 |
+
int x = g<B, T2>(); // #1 calls B::operator U1 T1::*
|
| 67 |
+
// #2 calls B::operator U1 T2::*
|
| 68 |
```
|
| 69 |
|
| 70 |
— *end example*]
|
| 71 |
|
| 72 |
+
In a friend declaration *declarator* whose *declarator-id* is a
|
| 73 |
+
*qualified-id* whose lookup context [[basic.lookup.qual]] is a class or
|
| 74 |
+
namespace S, lookup for an unqualified name that appears after the
|
| 75 |
+
*declarator-id* performs a search in the scope associated with S. If
|
| 76 |
+
that lookup finds nothing, it undergoes unqualified name lookup.
|
|
|
|
| 77 |
|
| 78 |
+
[*Example 2*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
+
using I = int;
|
| 82 |
+
using D = double;
|
| 83 |
+
namespace A {
|
| 84 |
+
inline namespace N {using C = char; }
|
| 85 |
+
using F = float;
|
| 86 |
+
void f(I);
|
| 87 |
+
void f(D);
|
| 88 |
+
void f(C);
|
| 89 |
+
void f(F);
|
| 90 |
+
}
|
| 91 |
+
struct X0 {using F = float; };
|
| 92 |
+
struct W {
|
| 93 |
+
using D = void;
|
| 94 |
+
struct X : X0 {
|
| 95 |
+
void g(I);
|
| 96 |
+
void g(::D);
|
| 97 |
+
void g(F);
|
| 98 |
+
};
|
| 99 |
+
};
|
| 100 |
+
namespace B {
|
| 101 |
+
typedef short I, F;
|
| 102 |
+
class Y {
|
| 103 |
+
friend void A::f(I); // error: no void A::f(short)
|
| 104 |
+
friend void A::f(D); // OK
|
| 105 |
+
friend void A::f(C); // error: A::N::C not found
|
| 106 |
+
friend void A::f(F); // OK
|
| 107 |
+
friend void W::X::g(I); // error: no void X::g(short)
|
| 108 |
+
friend void W::X::g(D); // OK
|
| 109 |
+
friend void W::X::g(F); // OK
|
| 110 |
+
};
|
| 111 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
```
|
| 113 |
|
| 114 |
— *end example*]
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|