- tmp/tmp0zsgm6gm/{from.md → to.md} +129 -110
tmp/tmp0zsgm6gm/{from.md → to.md}
RENAMED
|
@@ -1,15 +1,19 @@
|
|
| 1 |
### Argument-dependent name lookup <a id="basic.lookup.argdep">[[basic.lookup.argdep]]</a>
|
| 2 |
|
| 3 |
When the *postfix-expression* in a function call [[expr.call]] is an
|
| 4 |
-
*unqualified-id*,
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
[*Example 1*:
|
| 13 |
|
| 14 |
``` cpp
|
| 15 |
namespace N {
|
|
@@ -17,132 +21,125 @@ namespace N {
|
|
| 17 |
void f(S);
|
| 18 |
}
|
| 19 |
|
| 20 |
void g() {
|
| 21 |
N::S s;
|
| 22 |
-
f(s); // OK
|
| 23 |
(f)(s); // error: N::f not considered; parentheses prevent argument-dependent lookup
|
| 24 |
}
|
| 25 |
```
|
| 26 |
|
| 27 |
— *end example*]
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
For each argument type `T` in the function call, there is a set of zero
|
| 30 |
-
or more *associated
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
types do not contribute to this set. The sets of namespaces and entities
|
| 36 |
-
are determined in the following way:
|
| 37 |
|
| 38 |
-
- If `T` is a fundamental type, its associated
|
| 39 |
-
entities are both empty.
|
| 40 |
- If `T` is a class type (including unions), its associated entities
|
| 41 |
are: the class itself; the class of which it is a member, if any; and
|
| 42 |
-
its direct and indirect base classes.
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
template
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
namespaces and entities are those associated with `U`.
|
| 58 |
-
- If `T` is a function type, its associated namespaces and entities are
|
| 59 |
-
those associated with the function parameter types and those
|
| 60 |
-
associated with the return type.
|
| 61 |
- If `T` is a pointer to a member function of a class `X`, its
|
| 62 |
-
associated
|
| 63 |
-
|
| 64 |
-
associated with `X`.
|
| 65 |
- If `T` is a pointer to a data member of class `X`, its associated
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
and return type. Additionally, if the aforementioned overload set is
|
| 77 |
-
named with a *template-id*, its associated entities and namespaces also
|
| 78 |
-
include those of its type *template-argument*s and its template
|
| 79 |
-
*template-argument*s.
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
- a
|
| 86 |
-
- a
|
| 87 |
-
or
|
| 88 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
[
|
| 96 |
-
types can include namespaces and entities already considered by the
|
| 97 |
-
ordinary unqualified lookup. — *end note*]
|
| 98 |
|
| 99 |
[*Example 2*:
|
| 100 |
|
| 101 |
-
``` cpp
|
| 102 |
-
namespace NS {
|
| 103 |
-
class T { };
|
| 104 |
-
void f(T);
|
| 105 |
-
void g(T, int);
|
| 106 |
-
}
|
| 107 |
-
NS::T parm;
|
| 108 |
-
void g(NS::T, float);
|
| 109 |
-
int main() {
|
| 110 |
-
f(parm); // OK: calls NS::f
|
| 111 |
-
extern void g(NS::T, float);
|
| 112 |
-
g(parm, 1); // OK: calls g(NS::T, float)
|
| 113 |
-
}
|
| 114 |
-
```
|
| 115 |
-
|
| 116 |
-
— *end example*]
|
| 117 |
-
|
| 118 |
-
When considering an associated namespace `N`, the lookup is the same as
|
| 119 |
-
the lookup performed when `N` is used as a qualifier [[namespace.qual]]
|
| 120 |
-
except that:
|
| 121 |
-
|
| 122 |
-
- Any *using-directive*s in `N` are ignored.
|
| 123 |
-
- All names except those of (possibly overloaded) functions and function
|
| 124 |
-
templates are ignored.
|
| 125 |
-
- Any namespace-scope friend functions or friend function templates
|
| 126 |
-
[[class.friend]] declared in classes with reachable definitions in the
|
| 127 |
-
set of associated entities are visible within their respective
|
| 128 |
-
namespaces even if they are not visible during an ordinary lookup
|
| 129 |
-
[[namespace.memdef]].
|
| 130 |
-
- Any exported declaration `D` in `N` declared within the purview of a
|
| 131 |
-
named module `M` [[module.interface]] is visible if there is an
|
| 132 |
-
associated entity attached to `M` with the same innermost enclosing
|
| 133 |
-
non-inline namespace as `D`.
|
| 134 |
-
- If the lookup is for a dependent name ([[temp.dep]],
|
| 135 |
-
[[temp.dep.candidate]]), any declaration `D` in `N` is visible if `D`
|
| 136 |
-
would be visible to qualified name lookup [[namespace.qual]] at any
|
| 137 |
-
point in the instantiation context [[module.context]] of the lookup,
|
| 138 |
-
unless `D` is declared in another translation unit, attached to the
|
| 139 |
-
global module, and is either discarded [[module.global.frag]] or has
|
| 140 |
-
internal linkage.
|
| 141 |
-
|
| 142 |
-
[*Example 3*:
|
| 143 |
-
|
| 144 |
Translation unit #1
|
| 145 |
|
| 146 |
``` cpp
|
| 147 |
export module M;
|
| 148 |
namespace R {
|
|
@@ -186,5 +183,27 @@ void test() {
|
|
| 186 |
}
|
| 187 |
```
|
| 188 |
|
| 189 |
— *end example*]
|
| 190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
### Argument-dependent name lookup <a id="basic.lookup.argdep">[[basic.lookup.argdep]]</a>
|
| 2 |
|
| 3 |
When the *postfix-expression* in a function call [[expr.call]] is an
|
| 4 |
+
*unqualified-id*, and unqualified lookup [[basic.lookup.unqual]] for the
|
| 5 |
+
name in the *unqualified-id* does not find any
|
| 6 |
+
|
| 7 |
+
- declaration of a class member, or
|
| 8 |
+
- function declaration inhabiting a block scope, or
|
| 9 |
+
- declaration not of a function or function template
|
| 10 |
+
|
| 11 |
+
then lookup for the name also includes the result of
|
| 12 |
+
*argument-dependent lookup* in a set of associated namespaces that
|
| 13 |
+
depends on the types of the arguments (and for template template
|
| 14 |
+
arguments, the namespace of the template argument), as specified below.
|
| 15 |
|
| 16 |
[*Example 1*:
|
| 17 |
|
| 18 |
``` cpp
|
| 19 |
namespace N {
|
|
|
|
| 21 |
void f(S);
|
| 22 |
}
|
| 23 |
|
| 24 |
void g() {
|
| 25 |
N::S s;
|
| 26 |
+
f(s); // OK, calls N::f
|
| 27 |
(f)(s); // error: N::f not considered; parentheses prevent argument-dependent lookup
|
| 28 |
}
|
| 29 |
```
|
| 30 |
|
| 31 |
— *end example*]
|
| 32 |
|
| 33 |
+
[*Note 1*:
|
| 34 |
+
|
| 35 |
+
For purposes of determining (during parsing) whether an expression is a
|
| 36 |
+
*postfix-expression* for a function call, the usual name lookup rules
|
| 37 |
+
apply. In some cases a name followed by `<` is treated as a
|
| 38 |
+
*template-name* even though name lookup did not find a *template-name*
|
| 39 |
+
(see [[temp.names]]). For example,
|
| 40 |
+
|
| 41 |
+
``` cpp
|
| 42 |
+
int h;
|
| 43 |
+
void g();
|
| 44 |
+
namespace N {
|
| 45 |
+
struct A {};
|
| 46 |
+
template <class T> int f(T);
|
| 47 |
+
template <class T> int g(T);
|
| 48 |
+
template <class T> int h(T);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
int x = f<N::A>(N::A()); // OK, lookup of f finds nothing, f treated as template name
|
| 52 |
+
int y = g<N::A>(N::A()); // OK, lookup of g finds a function, g treated as template name
|
| 53 |
+
int z = h<N::A>(N::A()); // error: h< does not begin a template-id
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
The rules have no effect on the syntactic interpretation of an
|
| 57 |
+
expression. For example,
|
| 58 |
+
|
| 59 |
+
``` cpp
|
| 60 |
+
typedef int f;
|
| 61 |
+
namespace N {
|
| 62 |
+
struct A {
|
| 63 |
+
friend void f(A &);
|
| 64 |
+
operator int();
|
| 65 |
+
void g(A a) {
|
| 66 |
+
int i = f(a); // f is the typedef, not the friend function: equivalent to int(a)
|
| 67 |
+
}
|
| 68 |
+
};
|
| 69 |
+
}
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
Because the expression is not a function call, argument-dependent name
|
| 73 |
+
lookup does not apply and the friend function `f` is not found.
|
| 74 |
+
|
| 75 |
+
— *end note*]
|
| 76 |
+
|
| 77 |
For each argument type `T` in the function call, there is a set of zero
|
| 78 |
+
or more *associated entities* to be considered. The set of entities is
|
| 79 |
+
determined entirely by the types of the function arguments (and any
|
| 80 |
+
template template arguments). Any *typedef-name*s and
|
| 81 |
+
*using-declaration*s used to specify the types do not contribute to this
|
| 82 |
+
set. The set of entities is determined in the following way:
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
- If `T` is a fundamental type, its associated set of entities is empty.
|
|
|
|
| 85 |
- If `T` is a class type (including unions), its associated entities
|
| 86 |
are: the class itself; the class of which it is a member, if any; and
|
| 87 |
+
its direct and indirect base classes. Furthermore, if `T` is a class
|
| 88 |
+
template specialization, its associated entities also include: the
|
| 89 |
+
entities associated with the types of the template arguments provided
|
| 90 |
+
for template type parameters; the templates used as template template
|
| 91 |
+
arguments; and the classes of which any member templates used as
|
| 92 |
+
template template arguments are members. \[*Note 2*: Non-type template
|
| 93 |
+
arguments do not contribute to the set of associated
|
| 94 |
+
entities. — *end note*]
|
| 95 |
+
- If `T` is an enumeration type, its associated entities are `T` and, if
|
| 96 |
+
it is a class member, the member’s class.
|
| 97 |
+
- If `T` is a pointer to `U` or an array of `U`, its associated entities
|
| 98 |
+
are those associated with `U`.
|
| 99 |
+
- If `T` is a function type, its associated entities are those
|
| 100 |
+
associated with the function parameter types and those associated with
|
| 101 |
+
the return type.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
- If `T` is a pointer to a member function of a class `X`, its
|
| 103 |
+
associated entities are those associated with the function parameter
|
| 104 |
+
types and return type, together with those associated with `X`.
|
|
|
|
| 105 |
- If `T` is a pointer to a data member of class `X`, its associated
|
| 106 |
+
entities are those associated with the member type together with those
|
| 107 |
+
associated with `X`.
|
| 108 |
|
| 109 |
+
In addition, if the argument is an overload set or the address of such a
|
| 110 |
+
set, its associated entities are the union of those associated with each
|
| 111 |
+
of the members of the set, i.e., the entities associated with its
|
| 112 |
+
parameter types and return type. Additionally, if the aforementioned
|
| 113 |
+
overload set is named with a *template-id*, its associated entities also
|
| 114 |
+
include its template *template-argument*s and those associated with its
|
| 115 |
+
type *template-argument*s.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
The *associated namespaces* for a call are the innermost enclosing
|
| 118 |
+
non-inline namespaces for its associated entities as well as every
|
| 119 |
+
element of the inline namespace set [[namespace.def]] of those
|
| 120 |
+
namespaces. Argument-dependent lookup finds all declarations of
|
| 121 |
+
functions and function templates that
|
| 122 |
|
| 123 |
+
- are found by a search of any associated namespace, or
|
| 124 |
+
- are declared as a friend [[class.friend]] of any class with a
|
| 125 |
+
reachable definition in the set of associated entities, or
|
| 126 |
+
- are exported, are attached to a named module `M` [[module.interface]],
|
| 127 |
+
do not appear in the translation unit containing the point of the
|
| 128 |
+
lookup, and have the same innermost enclosing non-inline namespace
|
| 129 |
+
scope as a declaration of an associated entity attached to `M`
|
| 130 |
+
[[basic.link]].
|
| 131 |
|
| 132 |
+
If the lookup is for a dependent name
|
| 133 |
+
[[temp.dep]], [[temp.dep.candidate]], the above lookup is also performed
|
| 134 |
+
from each point in the instantiation context [[module.context]] of the
|
| 135 |
+
lookup, additionally ignoring any declaration that appears in another
|
| 136 |
+
translation unit, is attached to the global module, and is either
|
| 137 |
+
discarded [[module.global.frag]] or has internal linkage.
|
|
|
|
|
|
|
| 138 |
|
| 139 |
[*Example 2*:
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
Translation unit #1
|
| 142 |
|
| 143 |
``` cpp
|
| 144 |
export module M;
|
| 145 |
namespace R {
|
|
|
|
| 183 |
}
|
| 184 |
```
|
| 185 |
|
| 186 |
— *end example*]
|
| 187 |
|
| 188 |
+
[*Note 3*: The associated namespace can include namespaces already
|
| 189 |
+
considered by ordinary unqualified lookup. — *end note*]
|
| 190 |
+
|
| 191 |
+
[*Example 3*:
|
| 192 |
+
|
| 193 |
+
``` cpp
|
| 194 |
+
namespace NS {
|
| 195 |
+
class T { };
|
| 196 |
+
void f(T);
|
| 197 |
+
void g(T, int);
|
| 198 |
+
}
|
| 199 |
+
NS::T parm;
|
| 200 |
+
void g(NS::T, float);
|
| 201 |
+
int main() {
|
| 202 |
+
f(parm); // OK, calls NS::f
|
| 203 |
+
extern void g(NS::T, float);
|
| 204 |
+
g(parm, 1); // OK, calls g(NS::T, float)
|
| 205 |
+
}
|
| 206 |
+
```
|
| 207 |
+
|
| 208 |
+
— *end example*]
|
| 209 |
+
|