- tmp/tmppcjfwkuu/{from.md → to.md} +77 -102
tmp/tmppcjfwkuu/{from.md → to.md}
RENAMED
|
@@ -1,69 +1,60 @@
|
|
| 1 |
-
## Member name lookup <a id="class.member.lookup">[[class.member.lookup]]</a>
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
*
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
The
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
is
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
S(
|
| 45 |
-
|
| 46 |
-
The following steps define the result of merging lookup set S(f,Bᵢ) into
|
| 47 |
-
the intermediate S(f,C):
|
| 48 |
-
|
| 49 |
-
- If each of the subobject members of S(f,Bᵢ) is a base class subobject
|
| 50 |
-
of at least one of the subobject members of S(f,C), or if S(f,Bᵢ) is
|
| 51 |
-
empty, S(f,C) is unchanged and the merge is complete. Conversely, if
|
| 52 |
-
each of the subobject members of S(f,C) is a base class subobject of
|
| 53 |
-
at least one of the subobject members of S(f,Bᵢ), or if S(f,C) is
|
| 54 |
-
empty, the new S(f,C) is a copy of S(f,Bᵢ).
|
| 55 |
-
- Otherwise, if the declaration sets of S(f,Bᵢ) and S(f,C) differ, the
|
| 56 |
-
merge is ambiguous: the new S(f,C) is a lookup set with an invalid
|
| 57 |
declaration set and the union of the subobject sets. In subsequent
|
| 58 |
merges, an invalid declaration set is considered different from any
|
| 59 |
other.
|
| 60 |
-
- Otherwise, the new S(
|
| 61 |
declarations and the union of the subobject sets.
|
| 62 |
|
| 63 |
-
The result of
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
|
| 66 |
[*Example 1*:
|
| 67 |
|
| 68 |
``` cpp
|
| 69 |
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
|
|
@@ -76,50 +67,34 @@ int main() {
|
|
| 76 |
F f;
|
| 77 |
f.x = 0; // OK, lookup finds E::x
|
| 78 |
}
|
| 79 |
```
|
| 80 |
|
| 81 |
-
S(x,F) is unambiguous because the `A` and `B` base class subobjects
|
| 82 |
-
`D` are also base class subobjects of `E`, so S(x,D) is discarded
|
| 83 |
-
first merge step.
|
| 84 |
|
| 85 |
— *end example*]
|
| 86 |
|
| 87 |
-
If
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
name
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
[*
|
|
|
|
| 93 |
|
| 94 |
-
|
| 95 |
-
struct A {
|
| 96 |
-
int f();
|
| 97 |
-
};
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
``` cpp
|
| 101 |
-
struct B {
|
| 102 |
-
int f();
|
| 103 |
-
};
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
``` cpp
|
| 107 |
-
struct C : A, B {
|
| 108 |
-
int f() { return A::f() + B::f(); }
|
| 109 |
-
};
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
— *end example*]
|
| 113 |
-
|
| 114 |
-
[*Note 2*: A static member, a nested type or an enumerator defined in a
|
| 115 |
base class `T` can unambiguously be found even if an object has more
|
| 116 |
than one base class subobject of type `T`. Two base class subobjects
|
| 117 |
share the non-static member subobjects of their common virtual base
|
| 118 |
classes. — *end note*]
|
| 119 |
|
| 120 |
-
[*Example
|
| 121 |
|
| 122 |
``` cpp
|
| 123 |
struct V {
|
| 124 |
int v;
|
| 125 |
};
|
|
@@ -131,27 +106,27 @@ struct A {
|
|
| 131 |
struct B : A, virtual V { };
|
| 132 |
struct C : A, virtual V { };
|
| 133 |
struct D : B, C { };
|
| 134 |
|
| 135 |
void f(D* pd) {
|
| 136 |
-
pd->v++; // OK
|
| 137 |
-
pd->s++; // OK
|
| 138 |
-
int i = pd->e; // OK
|
| 139 |
pd->a++; // error: ambiguous: two a{s} in D
|
| 140 |
}
|
| 141 |
```
|
| 142 |
|
| 143 |
— *end example*]
|
| 144 |
|
| 145 |
-
[*Note
|
| 146 |
can be reached along a path through the subobject lattice that does not
|
| 147 |
pass through the hiding declaration. This is not an ambiguity. The
|
| 148 |
identical use with non-virtual base classes is an ambiguity; in that
|
| 149 |
case there is no unique instance of the name that hides all the
|
| 150 |
others. — *end note*]
|
| 151 |
|
| 152 |
-
[*Example
|
| 153 |
|
| 154 |
``` cpp
|
| 155 |
struct V { int f(); int x; };
|
| 156 |
struct W { int g(); int y; };
|
| 157 |
struct B : virtual V, W {
|
|
@@ -172,12 +147,12 @@ As illustrated in Figure [[fig:class.lookup]], the names declared in
|
|
| 172 |
the names declared in the right-hand instance of `W` are not hidden at
|
| 173 |
all.
|
| 174 |
|
| 175 |
``` cpp
|
| 176 |
void D::glorp() {
|
| 177 |
-
x++; // OK
|
| 178 |
-
f(); // OK
|
| 179 |
y++; // error: B::y and C's W::y
|
| 180 |
g(); // error: B::g() and C's W::g()
|
| 181 |
}
|
| 182 |
```
|
| 183 |
|
|
@@ -186,11 +161,11 @@ void D::glorp() {
|
|
| 186 |
An explicit or implicit conversion from a pointer to or an expression
|
| 187 |
designating an object of a derived class to a pointer or reference to
|
| 188 |
one of its base classes shall unambiguously refer to a unique object
|
| 189 |
representing the base class.
|
| 190 |
|
| 191 |
-
[*Example
|
| 192 |
|
| 193 |
``` cpp
|
| 194 |
struct V { };
|
| 195 |
struct A { };
|
| 196 |
struct B : A, virtual V { };
|
|
@@ -199,21 +174,21 @@ struct D : B, C { };
|
|
| 199 |
|
| 200 |
void g() {
|
| 201 |
D d;
|
| 202 |
B* pb = &d;
|
| 203 |
A* pa = &d; // error: ambiguous: C's A or B's A?
|
| 204 |
-
V* pv = &d; // OK
|
| 205 |
}
|
| 206 |
```
|
| 207 |
|
| 208 |
— *end example*]
|
| 209 |
|
| 210 |
-
[*Note
|
| 211 |
-
name found in multiple subobjects might still be ambiguous
|
| 212 |
-
[[conv.mem]], [[expr.ref]], [[class.access.base]]
|
| 213 |
|
| 214 |
-
[*Example
|
| 215 |
|
| 216 |
``` cpp
|
| 217 |
struct B1 {
|
| 218 |
void f();
|
| 219 |
static void f(int);
|
|
|
|
| 1 |
+
### Member name lookup <a id="class.member.lookup">[[class.member.lookup]]</a>
|
| 2 |
+
|
| 3 |
+
A *search* in a scope X for a name M from a program point P is a single
|
| 4 |
+
search in X for M from P unless X is the scope of a class or class
|
| 5 |
+
template T, in which case the following steps define the result of the
|
| 6 |
+
search.
|
| 7 |
+
|
| 8 |
+
[*Note 1*: The result differs only if M is a *conversion-function-id*
|
| 9 |
+
or if the single search would find nothing. — *end note*]
|
| 10 |
+
|
| 11 |
+
The *lookup set* for a name N in a class or class template C, called
|
| 12 |
+
S(N,C), consists of two component sets: the *declaration set*, a set of
|
| 13 |
+
members named N; and the *subobject set*, a set of subobjects where
|
| 14 |
+
declarations of these members were found (possibly via
|
| 15 |
+
*using-declaration*s). In the declaration set, type declarations
|
| 16 |
+
(including injected-class-names) are replaced by the types they
|
| 17 |
+
designate. S(N,C) is calculated as follows:
|
| 18 |
+
|
| 19 |
+
The declaration set is the result of a single search in the scope of C
|
| 20 |
+
for N from immediately after the *class-specifier* of C if P is in a
|
| 21 |
+
complete-class context of C or from P otherwise. If the resulting
|
| 22 |
+
declaration set is not empty, the subobject set contains C itself, and
|
| 23 |
+
calculation is complete.
|
| 24 |
+
|
| 25 |
+
Otherwise (i.e., C does not contain a declaration of N or the resulting
|
| 26 |
+
declaration set is empty), S(N,C) is initially empty. Calculate the
|
| 27 |
+
lookup set for N in each direct non-dependent [[temp.dep.type]] base
|
| 28 |
+
class subobject Bᵢ, and merge each such lookup set S(N,Bᵢ) in turn into
|
| 29 |
+
S(N,C).
|
| 30 |
+
|
| 31 |
+
[*Note 2*: If C is incomplete, only base classes whose *base-specifier*
|
| 32 |
+
appears before P are considered. If C is an instantiated class, its base
|
| 33 |
+
classes are not dependent. — *end note*]
|
| 34 |
+
|
| 35 |
+
The following steps define the result of merging lookup set S(N,Bᵢ) into
|
| 36 |
+
the intermediate S(N,C):
|
| 37 |
+
|
| 38 |
+
- If each of the subobject members of S(N,Bᵢ) is a base class subobject
|
| 39 |
+
of at least one of the subobject members of S(N,C), or if S(N,Bᵢ) is
|
| 40 |
+
empty, S(N,C) is unchanged and the merge is complete. Conversely, if
|
| 41 |
+
each of the subobject members of S(N,C) is a base class subobject of
|
| 42 |
+
at least one of the subobject members of S(N,Bᵢ), or if S(N,C) is
|
| 43 |
+
empty, the new S(N,C) is a copy of S(N,Bᵢ).
|
| 44 |
+
- Otherwise, if the declaration sets of S(N,Bᵢ) and S(N,C) differ, the
|
| 45 |
+
merge is ambiguous: the new S(N,C) is a lookup set with an invalid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
declaration set and the union of the subobject sets. In subsequent
|
| 47 |
merges, an invalid declaration set is considered different from any
|
| 48 |
other.
|
| 49 |
+
- Otherwise, the new S(N,C) is a lookup set with the shared set of
|
| 50 |
declarations and the union of the subobject sets.
|
| 51 |
|
| 52 |
+
The result of the search is the declaration set of S(M,T). If it is an
|
| 53 |
+
invalid set, the program is ill-formed. If it differs from the result of
|
| 54 |
+
a search in T for M in a complete-class context [[class.mem]] of T, the
|
| 55 |
+
program is ill-formed, no diagnostic required.
|
| 56 |
|
| 57 |
[*Example 1*:
|
| 58 |
|
| 59 |
``` cpp
|
| 60 |
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
|
|
|
|
| 67 |
F f;
|
| 68 |
f.x = 0; // OK, lookup finds E::x
|
| 69 |
}
|
| 70 |
```
|
| 71 |
|
| 72 |
+
S(`x`,`F`) is unambiguous because the `A` and `B` base class subobjects
|
| 73 |
+
of `D` are also base class subobjects of `E`, so S(`x`,`D`) is discarded
|
| 74 |
+
in the first merge step.
|
| 75 |
|
| 76 |
— *end example*]
|
| 77 |
|
| 78 |
+
If M is a non-dependent *conversion-function-id*, conversion function
|
| 79 |
+
templates that are members of T are considered. For each such template
|
| 80 |
+
F, the lookup set S(t,T) is constructed, considering a function template
|
| 81 |
+
declaration to have the name t only if it corresponds to a declaration
|
| 82 |
+
of F [[basic.scope.scope]]. The members of the declaration set of each
|
| 83 |
+
such lookup set, which shall not be an invalid set, are included in the
|
| 84 |
+
result.
|
| 85 |
|
| 86 |
+
[*Note 3*: Overload resolution will discard those that cannot convert
|
| 87 |
+
to the type specified by M [[temp.over]]. — *end note*]
|
| 88 |
|
| 89 |
+
[*Note 4*: A static member, a nested type or an enumerator defined in a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
base class `T` can unambiguously be found even if an object has more
|
| 91 |
than one base class subobject of type `T`. Two base class subobjects
|
| 92 |
share the non-static member subobjects of their common virtual base
|
| 93 |
classes. — *end note*]
|
| 94 |
|
| 95 |
+
[*Example 2*:
|
| 96 |
|
| 97 |
``` cpp
|
| 98 |
struct V {
|
| 99 |
int v;
|
| 100 |
};
|
|
|
|
| 106 |
struct B : A, virtual V { };
|
| 107 |
struct C : A, virtual V { };
|
| 108 |
struct D : B, C { };
|
| 109 |
|
| 110 |
void f(D* pd) {
|
| 111 |
+
pd->v++; // OK, only one v (virtual)
|
| 112 |
+
pd->s++; // OK, only one s (static)
|
| 113 |
+
int i = pd->e; // OK, only one e (enumerator)
|
| 114 |
pd->a++; // error: ambiguous: two a{s} in D
|
| 115 |
}
|
| 116 |
```
|
| 117 |
|
| 118 |
— *end example*]
|
| 119 |
|
| 120 |
+
[*Note 5*: When virtual base classes are used, a hidden declaration
|
| 121 |
can be reached along a path through the subobject lattice that does not
|
| 122 |
pass through the hiding declaration. This is not an ambiguity. The
|
| 123 |
identical use with non-virtual base classes is an ambiguity; in that
|
| 124 |
case there is no unique instance of the name that hides all the
|
| 125 |
others. — *end note*]
|
| 126 |
|
| 127 |
+
[*Example 3*:
|
| 128 |
|
| 129 |
``` cpp
|
| 130 |
struct V { int f(); int x; };
|
| 131 |
struct W { int g(); int y; };
|
| 132 |
struct B : virtual V, W {
|
|
|
|
| 147 |
the names declared in the right-hand instance of `W` are not hidden at
|
| 148 |
all.
|
| 149 |
|
| 150 |
``` cpp
|
| 151 |
void D::glorp() {
|
| 152 |
+
x++; // OK, B::x hides V::x
|
| 153 |
+
f(); // OK, B::f() hides V::f()
|
| 154 |
y++; // error: B::y and C's W::y
|
| 155 |
g(); // error: B::g() and C's W::g()
|
| 156 |
}
|
| 157 |
```
|
| 158 |
|
|
|
|
| 161 |
An explicit or implicit conversion from a pointer to or an expression
|
| 162 |
designating an object of a derived class to a pointer or reference to
|
| 163 |
one of its base classes shall unambiguously refer to a unique object
|
| 164 |
representing the base class.
|
| 165 |
|
| 166 |
+
[*Example 4*:
|
| 167 |
|
| 168 |
``` cpp
|
| 169 |
struct V { };
|
| 170 |
struct A { };
|
| 171 |
struct B : A, virtual V { };
|
|
|
|
| 174 |
|
| 175 |
void g() {
|
| 176 |
D d;
|
| 177 |
B* pb = &d;
|
| 178 |
A* pa = &d; // error: ambiguous: C's A or B's A?
|
| 179 |
+
V* pv = &d; // OK, only one V subobject
|
| 180 |
}
|
| 181 |
```
|
| 182 |
|
| 183 |
— *end example*]
|
| 184 |
|
| 185 |
+
[*Note 6*: Even if the result of name lookup is unambiguous, use of a
|
| 186 |
+
name found in multiple subobjects might still be ambiguous
|
| 187 |
+
[[conv.mem]], [[expr.ref]], [[class.access.base]]. — *end note*]
|
| 188 |
|
| 189 |
+
[*Example 5*:
|
| 190 |
|
| 191 |
``` cpp
|
| 192 |
struct B1 {
|
| 193 |
void f();
|
| 194 |
static void f(int);
|