tmp/tmpy0we9v5m/{from.md → to.md}
RENAMED
|
@@ -17,12 +17,31 @@ function call is described in [[basic.lookup.argdep]].
|
|
| 17 |
|
| 18 |
[*Note 1*:
|
| 19 |
|
| 20 |
For purposes of determining (during parsing) whether an expression is a
|
| 21 |
*postfix-expression* for a function call, the usual name lookup rules
|
| 22 |
-
apply.
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
``` cpp
|
| 26 |
typedef int f;
|
| 27 |
namespace N {
|
| 28 |
struct A {
|
|
@@ -34,11 +53,11 @@ namespace N {
|
|
| 34 |
};
|
| 35 |
}
|
| 36 |
```
|
| 37 |
|
| 38 |
Because the expression is not a function call, the argument-dependent
|
| 39 |
-
name lookup
|
| 40 |
function `f` is not found.
|
| 41 |
|
| 42 |
— *end note*]
|
| 43 |
|
| 44 |
A name used in global scope, outside of any function, class or
|
|
@@ -48,15 +67,15 @@ scope.
|
|
| 48 |
A name used in a user-declared namespace outside of the definition of
|
| 49 |
any function or class shall be declared before its use in that namespace
|
| 50 |
or before its use in a namespace enclosing its namespace.
|
| 51 |
|
| 52 |
In the definition of a function that is a member of namespace `N`, a
|
| 53 |
-
name used after the function’s *declarator-id*[^
|
| 54 |
before its use in the block in which it is used or in one of its
|
| 55 |
-
enclosing blocks
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
[*Example 1*:
|
| 60 |
|
| 61 |
``` cpp
|
| 62 |
namespace A {
|
|
@@ -74,22 +93,21 @@ void A::N::f() {
|
|
| 74 |
}
|
| 75 |
```
|
| 76 |
|
| 77 |
— *end example*]
|
| 78 |
|
| 79 |
-
A name used in the definition of a class `X` outside of a
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
class definition[^5] shall be declared in one of the following ways:
|
| 83 |
|
| 84 |
-
- before its use in class `X` or be a member of a base class of `X`
|
| 85 |
-
[[class.member.lookup]]
|
| 86 |
-
- if `X` is a nested class of class `Y`
|
| 87 |
definition of `X` in `Y`, or shall be a member of a base class of `Y`
|
| 88 |
(this lookup applies in turn to `Y`’s enclosing classes, starting with
|
| 89 |
-
the innermost enclosing class),[^
|
| 90 |
-
- if `X` is a local class
|
| 91 |
local class, before the definition of class `X` in a block enclosing
|
| 92 |
the definition of class `X`, or
|
| 93 |
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 94 |
that is a member of `N`, or is a local class or a nested class within
|
| 95 |
a local class of a function that is a member of `N`, before the
|
|
@@ -122,36 +140,34 @@ namespace N {
|
|
| 122 |
```
|
| 123 |
|
| 124 |
— *end example*]
|
| 125 |
|
| 126 |
[*Note 2*: When looking for a prior declaration of a class or function
|
| 127 |
-
introduced by a
|
| 128 |
enclosing namespace scope are not considered; see
|
| 129 |
[[namespace.memdef]]. — *end note*]
|
| 130 |
|
| 131 |
[*Note 3*: [[basic.scope.class]] further describes the restrictions on
|
| 132 |
the use of names in a class definition. [[class.nest]] further describes
|
| 133 |
the restrictions on the use of names in nested class definitions.
|
| 134 |
[[class.local]] further describes the restrictions on the use of names
|
| 135 |
in local class definitions. — *end note*]
|
| 136 |
|
| 137 |
-
For the members of a class `X`, a name used in a
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
definition of `X`, following the member’s *declarator-id*[^7], shall be
|
| 142 |
-
declared in one of the following ways:
|
| 143 |
|
| 144 |
- before its use in the block in which it is used or in an enclosing
|
| 145 |
-
block
|
| 146 |
-
- shall be a member of class `X` or be a member of a base class of `X`
|
| 147 |
-
[[class.member.lookup]]
|
| 148 |
-
- if `X` is a nested class of class `Y`
|
| 149 |
member of `Y`, or shall be a member of a base class of `Y` (this
|
| 150 |
lookup applies in turn to `Y`’s enclosing classes, starting with the
|
| 151 |
-
innermost enclosing class),[^
|
| 152 |
-
- if `X` is a local class
|
| 153 |
local class, before the definition of class `X` in a block enclosing
|
| 154 |
the definition of class `X`, or
|
| 155 |
- if `X` is a member of namespace `N`, or is a nested class of a class
|
| 156 |
that is a member of `N`, or is a local class or a nested class within
|
| 157 |
a local class of a function that is a member of `N`, before the use of
|
|
@@ -188,21 +204,21 @@ restrictions on the use of names in member function definitions.
|
|
| 188 |
[[class.nest]] further describes the restrictions on the use of names in
|
| 189 |
the scope of nested classes. [[class.local]] further describes the
|
| 190 |
restrictions on the use of names in local class
|
| 191 |
definitions. — *end note*]
|
| 192 |
|
| 193 |
-
Name lookup for a name used in the definition of a
|
| 194 |
-
[[class.friend]]
|
| 195 |
proceed as described for lookup in member function definitions. If the
|
| 196 |
-
|
| 197 |
-
lookup in the
|
| 198 |
-
|
| 199 |
|
| 200 |
-
In a
|
| 201 |
function declarator and not part of a *template-argument* in the
|
| 202 |
*declarator-id* is first looked up in the scope of the member function’s
|
| 203 |
-
class
|
| 204 |
part of a *template-argument* in the *declarator-id*, the look up is as
|
| 205 |
described for unqualified names in the definition of the class granting
|
| 206 |
friendship.
|
| 207 |
|
| 208 |
[*Example 4*:
|
|
@@ -223,14 +239,14 @@ struct B {
|
|
| 223 |
};
|
| 224 |
```
|
| 225 |
|
| 226 |
— *end example*]
|
| 227 |
|
| 228 |
-
During the lookup for a name used as a default argument
|
| 229 |
-
[[dcl.fct.default]]
|
| 230 |
-
|
| 231 |
-
[[class.base.init]]
|
| 232 |
the names of entities declared in the block, class or namespace scopes
|
| 233 |
containing the function declaration.
|
| 234 |
|
| 235 |
[*Note 5*: [[dcl.fct.default]] further describes the restrictions on
|
| 236 |
the use of names in default arguments. [[class.base.init]] further
|
|
@@ -240,13 +256,13 @@ describes the restrictions on the use of names in a
|
|
| 240 |
During the lookup of a name used in the *constant-expression* of an
|
| 241 |
*enumerator-definition*, previously declared *enumerator*s of the
|
| 242 |
enumeration are visible and hide the names of entities declared in the
|
| 243 |
block, class, or namespace scopes containing the *enum-specifier*.
|
| 244 |
|
| 245 |
-
A name used in the definition of a `static` data member of class `X`
|
| 246 |
-
[[class.static.data]]
|
| 247 |
-
|
| 248 |
|
| 249 |
[*Note 6*: [[class.static.data]] further describes the restrictions on
|
| 250 |
the use of names in the definition of a `static` data
|
| 251 |
member. — *end note*]
|
| 252 |
|
|
@@ -268,17 +284,17 @@ int i = 2;
|
|
| 268 |
int N::j = i; // N::j == 4
|
| 269 |
```
|
| 270 |
|
| 271 |
— *end example*]
|
| 272 |
|
| 273 |
-
A name used in the handler for a *function-try-block*
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
|
| 281 |
[*Note 7*: But function parameter names are found. — *end note*]
|
| 282 |
|
| 283 |
[*Note 8*: The rules for name lookup in template definitions are
|
| 284 |
described in [[temp.res]]. — *end note*]
|
|
|
|
| 17 |
|
| 18 |
[*Note 1*:
|
| 19 |
|
| 20 |
For purposes of determining (during parsing) whether an expression is a
|
| 21 |
*postfix-expression* for a function call, the usual name lookup rules
|
| 22 |
+
apply. In some cases a name followed by `<` is treated as a
|
| 23 |
+
*template-name* even though name lookup did not find a *template-name*
|
| 24 |
+
(see [[temp.names]]). For example,
|
| 25 |
+
|
| 26 |
+
``` cpp
|
| 27 |
+
int h;
|
| 28 |
+
void g();
|
| 29 |
+
namespace N {
|
| 30 |
+
struct A {};
|
| 31 |
+
template <class T> int f(T);
|
| 32 |
+
template <class T> int g(T);
|
| 33 |
+
template <class T> int h(T);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
int x = f<N::A>(N::A()); // OK: lookup of f finds nothing, f treated as template name
|
| 37 |
+
int y = g<N::A>(N::A()); // OK: lookup of g finds a function, g treated as template name
|
| 38 |
+
int z = h<N::A>(N::A()); // error: h< does not begin a template-id
|
| 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 {
|
|
|
|
| 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
|
|
|
|
| 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 |
namespace A {
|
|
|
|
| 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
|
|
|
|
| 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
|
|
|
|
| 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*:
|
|
|
|
| 239 |
};
|
| 240 |
```
|
| 241 |
|
| 242 |
— *end example*]
|
| 243 |
|
| 244 |
+
During the lookup for a name used as a default argument
|
| 245 |
+
[[dcl.fct.default]] in a function *parameter-declaration-clause* or used
|
| 246 |
+
in the *expression* of a *mem-initializer* for a constructor
|
| 247 |
+
[[class.base.init]], the function parameter names are visible and hide
|
| 248 |
the names of entities declared in the block, class or namespace scopes
|
| 249 |
containing the function declaration.
|
| 250 |
|
| 251 |
[*Note 5*: [[dcl.fct.default]] further describes the restrictions on
|
| 252 |
the use of names in default arguments. [[class.base.init]] further
|
|
|
|
| 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 |
|
|
|
|
| 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*]
|