tmp/tmpjm8fogjb/{from.md → to.md}
RENAMED
|
@@ -22,20 +22,22 @@ injected-class-names) are replaced by the types they designate. S(f,C)
|
|
| 22 |
is calculated as follows:
|
| 23 |
|
| 24 |
If `C` contains a declaration of the name `f`, the declaration set
|
| 25 |
contains every declaration of `f` declared in `C` that satisfies the
|
| 26 |
requirements of the language construct in which the lookup occurs.
|
| 27 |
-
|
|
|
|
| 28 |
[[basic.lookup.elab]]) or *base-specifier* (Clause [[class.derived]]),
|
| 29 |
for instance, ignores all non-type declarations, while looking up a name
|
| 30 |
in a *nested-name-specifier* ([[basic.lookup.qual]]) ignores function,
|
| 31 |
variable, and enumerator declarations. As another example, looking up a
|
| 32 |
name in a *using-declaration* ([[namespace.udecl]]) includes the
|
| 33 |
declaration of a class or enumeration that would ordinarily be hidden by
|
| 34 |
-
another declaration of that name in the same scope.
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
Otherwise (i.e., `C` does not contain a declaration of `f` or the
|
| 39 |
resulting declaration set is empty), S(f,C) is initially empty. If `C`
|
| 40 |
has base classes, calculate the lookup set for `f` in each direct base
|
| 41 |
class subobject Bᵢ, and merge each such lookup set S(f,Bᵢ) in turn into
|
|
@@ -59,10 +61,12 @@ the intermediate S(f,C):
|
|
| 59 |
declarations and the union of the subobject sets.
|
| 60 |
|
| 61 |
The result of name lookup for `f` in `C` is the declaration set of
|
| 62 |
S(f,C). If it is an invalid set, the program is ill-formed.
|
| 63 |
|
|
|
|
|
|
|
| 64 |
``` cpp
|
| 65 |
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
|
| 66 |
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
|
| 67 |
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
|
| 68 |
struct D: public virtual C { }; // S(x,D) = S(x,C)
|
|
@@ -72,18 +76,22 @@ int main() {
|
|
| 72 |
F f;
|
| 73 |
f.x = 0; // OK, lookup finds E::x
|
| 74 |
}
|
| 75 |
```
|
| 76 |
|
| 77 |
-
S(x,F) is unambiguous because the `A` and `B` base subobjects of
|
| 78 |
-
also base subobjects of `E`, so S(x,D) is discarded in the
|
| 79 |
-
step.
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
``` cpp
|
| 87 |
struct A {
|
| 88 |
int f();
|
| 89 |
};
|
|
@@ -99,14 +107,19 @@ struct B {
|
|
| 99 |
struct C : A, B {
|
| 100 |
int f() { return A::f() + B::f(); }
|
| 101 |
};
|
| 102 |
```
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
``` cpp
|
| 110 |
struct V {
|
| 111 |
int v;
|
| 112 |
};
|
|
@@ -125,15 +138,20 @@ void f(D* pd) {
|
|
| 125 |
int i = pd->e; // OK: only one e (enumerator)
|
| 126 |
pd->a++; // error, ambiguous: two a{s} in D
|
| 127 |
}
|
| 128 |
```
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
``` cpp
|
| 137 |
struct V { int f(); int x; };
|
| 138 |
struct W { int g(); int y; };
|
| 139 |
struct B : virtual V, W {
|
|
@@ -160,15 +178,19 @@ void D::glorp() {
|
|
| 160 |
y++; // error: B::y and C's W::y
|
| 161 |
g(); // error: B::g() and C's W::g()
|
| 162 |
}
|
| 163 |
```
|
| 164 |
|
|
|
|
|
|
|
| 165 |
An explicit or implicit conversion from a pointer to or an expression
|
| 166 |
designating an object of a derived class to a pointer or reference to
|
| 167 |
one of its base classes shall unambiguously refer to a unique object
|
| 168 |
representing the base class.
|
| 169 |
|
|
|
|
|
|
|
| 170 |
``` cpp
|
| 171 |
struct V { };
|
| 172 |
struct A { };
|
| 173 |
struct B : A, virtual V { };
|
| 174 |
struct C : A, virtual V { };
|
|
@@ -180,13 +202,17 @@ void g() {
|
|
| 180 |
A* pa = &d; // error, ambiguous: C's A or B's A?
|
| 181 |
V* pv = &d; // OK: only one V subobject
|
| 182 |
}
|
| 183 |
```
|
| 184 |
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
``` cpp
|
| 190 |
struct B1 {
|
| 191 |
void f();
|
| 192 |
static void f(int);
|
|
@@ -209,5 +235,7 @@ struct D: I1, I2, B2 {
|
|
| 209 |
int D::* mpD = &D::i; // Ambiguous conversion
|
| 210 |
}
|
| 211 |
};
|
| 212 |
```
|
| 213 |
|
|
|
|
|
|
|
|
|
| 22 |
is calculated as follows:
|
| 23 |
|
| 24 |
If `C` contains a declaration of the name `f`, the declaration set
|
| 25 |
contains every declaration of `f` declared in `C` that satisfies the
|
| 26 |
requirements of the language construct in which the lookup occurs.
|
| 27 |
+
|
| 28 |
+
[*Note 1*: Looking up a name in an *elaborated-type-specifier* (
|
| 29 |
[[basic.lookup.elab]]) or *base-specifier* (Clause [[class.derived]]),
|
| 30 |
for instance, ignores all non-type declarations, while looking up a name
|
| 31 |
in a *nested-name-specifier* ([[basic.lookup.qual]]) ignores function,
|
| 32 |
variable, and enumerator declarations. As another example, looking up a
|
| 33 |
name in a *using-declaration* ([[namespace.udecl]]) includes the
|
| 34 |
declaration of a class or enumeration that would ordinarily be hidden by
|
| 35 |
+
another declaration of that name in the same scope. — *end note*]
|
| 36 |
+
|
| 37 |
+
If the resulting declaration set is not empty, the subobject set
|
| 38 |
+
contains `C` itself, and calculation is complete.
|
| 39 |
|
| 40 |
Otherwise (i.e., `C` does not contain a declaration of `f` or the
|
| 41 |
resulting declaration set is empty), S(f,C) is initially empty. If `C`
|
| 42 |
has base classes, calculate the lookup set for `f` in each direct base
|
| 43 |
class subobject Bᵢ, and merge each such lookup set S(f,Bᵢ) in turn into
|
|
|
|
| 61 |
declarations and the union of the subobject sets.
|
| 62 |
|
| 63 |
The result of name lookup for `f` in `C` is the declaration set of
|
| 64 |
S(f,C). If it is an invalid set, the program is ill-formed.
|
| 65 |
|
| 66 |
+
[*Example 1*:
|
| 67 |
+
|
| 68 |
``` cpp
|
| 69 |
struct A { int x; }; // S(x,A) = { { A::x }, { A } }
|
| 70 |
struct B { float x; }; // S(x,B) = { { B::x }, { B } }
|
| 71 |
struct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }
|
| 72 |
struct D: public virtual C { }; // S(x,D) = S(x,C)
|
|
|
|
| 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 of
|
| 82 |
+
`D` are also base class subobjects of `E`, so S(x,D) is discarded in the
|
| 83 |
+
first merge step.
|
| 84 |
|
| 85 |
+
— *end example*]
|
| 86 |
+
|
| 87 |
+
If the name of an overloaded function is unambiguously found, overload
|
| 88 |
+
resolution ([[over.match]]) also takes place before access control.
|
| 89 |
+
Ambiguities can often be resolved by qualifying a name with its class
|
| 90 |
+
name.
|
| 91 |
+
|
| 92 |
+
[*Example 2*:
|
| 93 |
|
| 94 |
``` cpp
|
| 95 |
struct A {
|
| 96 |
int f();
|
| 97 |
};
|
|
|
|
| 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 3*:
|
| 121 |
|
| 122 |
``` cpp
|
| 123 |
struct V {
|
| 124 |
int v;
|
| 125 |
};
|
|
|
|
| 138 |
int i = pd->e; // OK: only one e (enumerator)
|
| 139 |
pd->a++; // error, ambiguous: two a{s} in D
|
| 140 |
}
|
| 141 |
```
|
| 142 |
|
| 143 |
+
— *end example*]
|
| 144 |
+
|
| 145 |
+
[*Note 3*: When virtual base classes are used, a hidden declaration
|
| 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 4*:
|
| 153 |
|
| 154 |
``` cpp
|
| 155 |
struct V { int f(); int x; };
|
| 156 |
struct W { int g(); int y; };
|
| 157 |
struct B : virtual V, W {
|
|
|
|
| 178 |
y++; // error: B::y and C's W::y
|
| 179 |
g(); // error: B::g() and C's W::g()
|
| 180 |
}
|
| 181 |
```
|
| 182 |
|
| 183 |
+
— *end example*]
|
| 184 |
+
|
| 185 |
An explicit or implicit conversion from a pointer to or an expression
|
| 186 |
designating an object of a derived class to a pointer or reference to
|
| 187 |
one of its base classes shall unambiguously refer to a unique object
|
| 188 |
representing the base class.
|
| 189 |
|
| 190 |
+
[*Example 5*:
|
| 191 |
+
|
| 192 |
``` cpp
|
| 193 |
struct V { };
|
| 194 |
struct A { };
|
| 195 |
struct B : A, virtual V { };
|
| 196 |
struct C : A, virtual V { };
|
|
|
|
| 202 |
A* pa = &d; // error, ambiguous: C's A or B's A?
|
| 203 |
V* pv = &d; // OK: only one V subobject
|
| 204 |
}
|
| 205 |
```
|
| 206 |
|
| 207 |
+
— *end example*]
|
| 208 |
+
|
| 209 |
+
[*Note 4*: Even if the result of name lookup is unambiguous, use of a
|
| 210 |
+
name found in multiple subobjects might still be ambiguous (
|
| 211 |
+
[[conv.mem]], [[expr.ref]], [[class.access.base]]). — *end note*]
|
| 212 |
+
|
| 213 |
+
[*Example 6*:
|
| 214 |
|
| 215 |
``` cpp
|
| 216 |
struct B1 {
|
| 217 |
void f();
|
| 218 |
static void f(int);
|
|
|
|
| 235 |
int D::* mpD = &D::i; // Ambiguous conversion
|
| 236 |
}
|
| 237 |
};
|
| 238 |
```
|
| 239 |
|
| 240 |
+
— *end example*]
|
| 241 |
+
|