-
Notifications
You must be signed in to change notification settings - Fork 0
/
d0008.cc
44 lines (36 loc) · 985 Bytes
/
d0008.cc
1
2
3
4
5
6
7
8
9
10
11
12
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
42
43
44
// d0008.cc
// tricky sequence of conversions, involving inheriting from template param
// template inheriting from its parameter
template <class T>
struct D : T {};
// mostly irrelevant
struct Q {};
// template with conversion operator to D<T>*
template <class T>
struct C {
C (Q &);
operator D<T> *();
};
struct A {};
struct B {};
// overloaded 'g'
int g(A*);
int g(B*);
void f()
{
Q q;
C<B> r(q);
// Force an instantiation of D<B>; does this help?
//
// Yes, this makes the conversion available. Now to find
// out how to make it available w/o a forced instantiation...
//
// Got it, 14.7.1 para 4 says what to do, and it's implemented
// in overload.cc, look for 'ensureClassBodyInstantiated'.
//D<B> dummy;
// expected sequence of conversions:
// 'r' is of type C<B>, so can convert to D<B>* (user defined conv)
// D<B> inherits from B, so D<B> can convert to B* (derived to base)
// B* is one of the allowed params of 'g'
g(r);
}