xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/member-template-access-expr.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc template<typename U, typename T>
f0(T t)3*f4a2713aSLionel Sambuc U f0(T t) {
4*f4a2713aSLionel Sambuc   return t.template get<U>();
5*f4a2713aSLionel Sambuc }
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc template<typename U, typename T>
f1(T t)8*f4a2713aSLionel Sambuc int &f1(T t) {
9*f4a2713aSLionel Sambuc   // FIXME: When we pretty-print this, we lose the "template" keyword.
10*f4a2713aSLionel Sambuc   return t.U::template get<int&>();
11*f4a2713aSLionel Sambuc }
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc struct X {
14*f4a2713aSLionel Sambuc   template<typename T> T get();
15*f4a2713aSLionel Sambuc };
16*f4a2713aSLionel Sambuc 
test_f0(X x)17*f4a2713aSLionel Sambuc void test_f0(X x) {
18*f4a2713aSLionel Sambuc   int i = f0<int>(x);
19*f4a2713aSLionel Sambuc   int &ir = f0<int&>(x);
20*f4a2713aSLionel Sambuc }
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc struct XDerived : public X {
23*f4a2713aSLionel Sambuc };
24*f4a2713aSLionel Sambuc 
test_f1(XDerived xd)25*f4a2713aSLionel Sambuc void test_f1(XDerived xd) {
26*f4a2713aSLionel Sambuc   int &ir = f1<X>(xd);
27*f4a2713aSLionel Sambuc }
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc // PR5213
30*f4a2713aSLionel Sambuc template <class T>
31*f4a2713aSLionel Sambuc struct A {};
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc template<class T>
34*f4a2713aSLionel Sambuc class B
35*f4a2713aSLionel Sambuc {
36*f4a2713aSLionel Sambuc   A<T> a_;
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc public:
39*f4a2713aSLionel Sambuc   void destroy();
40*f4a2713aSLionel Sambuc };
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc template<class T>
43*f4a2713aSLionel Sambuc void
destroy()44*f4a2713aSLionel Sambuc B<T>::destroy()
45*f4a2713aSLionel Sambuc {
46*f4a2713aSLionel Sambuc   a_.~A<T>();
47*f4a2713aSLionel Sambuc }
48*f4a2713aSLionel Sambuc 
do_destroy_B(B<int> b)49*f4a2713aSLionel Sambuc void do_destroy_B(B<int> b) {
50*f4a2713aSLionel Sambuc   b.destroy();
51*f4a2713aSLionel Sambuc }
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc struct X1 {
54*f4a2713aSLionel Sambuc   int* f1(int);
55*f4a2713aSLionel Sambuc   template<typename T> float* f1(T);
56*f4a2713aSLionel Sambuc 
57*f4a2713aSLionel Sambuc   static int* f2(int);
58*f4a2713aSLionel Sambuc   template<typename T> static float* f2(T);
59*f4a2713aSLionel Sambuc };
60*f4a2713aSLionel Sambuc 
test_X1(X1 x1)61*f4a2713aSLionel Sambuc void test_X1(X1 x1) {
62*f4a2713aSLionel Sambuc   float *fp1 = x1.f1<>(17);
63*f4a2713aSLionel Sambuc   float *fp2 = x1.f1<int>(3.14); // expected-warning {{implicit conversion from 'double' to 'int' changes value from 3.14 to 3}}
64*f4a2713aSLionel Sambuc   int *ip1 = x1.f1(17);
65*f4a2713aSLionel Sambuc   float *ip2 = x1.f1(3.14);
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc   float* (X1::*mf1)(int) = &X1::f1;
68*f4a2713aSLionel Sambuc   float* (X1::*mf2)(int) = &X1::f1<>;
69*f4a2713aSLionel Sambuc   float* (X1::*mf3)(float) = &X1::f1<float>;
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc   float* (*fp3)(int) = &X1::f2;
72*f4a2713aSLionel Sambuc   float* (*fp4)(int) = &X1::f2<>;
73*f4a2713aSLionel Sambuc   float* (*fp5)(float) = &X1::f2<float>;
74*f4a2713aSLionel Sambuc   float* (*fp6)(int) = X1::f2;
75*f4a2713aSLionel Sambuc   float* (*fp7)(int) = X1::f2<>;
76*f4a2713aSLionel Sambuc   float* (*fp8)(float) = X1::f2<float>;
77*f4a2713aSLionel Sambuc }
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc template<int A> struct X2 {
80*f4a2713aSLionel Sambuc   int m;
81*f4a2713aSLionel Sambuc };
82*f4a2713aSLionel Sambuc 
83*f4a2713aSLionel Sambuc template<typename T>
84*f4a2713aSLionel Sambuc struct X3 : T { };
85*f4a2713aSLionel Sambuc 
86*f4a2713aSLionel Sambuc template<typename T>
87*f4a2713aSLionel Sambuc struct X4 {
88*f4a2713aSLionel Sambuc   template<typename U>
89*f4a2713aSLionel Sambuc   void f(X2<sizeof(X3<U>().U::m)>);
90*f4a2713aSLionel Sambuc };
91*f4a2713aSLionel Sambuc 
f(X4<X3<int>> x4i)92*f4a2713aSLionel Sambuc void f(X4<X3<int> > x4i) {
93*f4a2713aSLionel Sambuc   X2<sizeof(int)> x2;
94*f4a2713aSLionel Sambuc   x4i.f<X2<sizeof(int)> >(x2);
95*f4a2713aSLionel Sambuc }
96*f4a2713aSLionel Sambuc 
97*f4a2713aSLionel Sambuc template<typename T>
98*f4a2713aSLionel Sambuc struct X5 {
99*f4a2713aSLionel Sambuc   template<typename U>
100*f4a2713aSLionel Sambuc   void f();
101*f4a2713aSLionel Sambuc 
gX5102*f4a2713aSLionel Sambuc   void g() {
103*f4a2713aSLionel Sambuc     this->f<T*>();
104*f4a2713aSLionel Sambuc   }
105*f4a2713aSLionel Sambuc };
106*f4a2713aSLionel Sambuc 
107*f4a2713aSLionel Sambuc namespace PR6021 {
108*f4a2713aSLionel Sambuc   template< class T1, class T2 >
109*f4a2713aSLionel Sambuc   class Outer
110*f4a2713aSLionel Sambuc   {
111*f4a2713aSLionel Sambuc   public: // Range operations
112*f4a2713aSLionel Sambuc     template< class X > X tmpl( const X* = 0 ) const;
113*f4a2713aSLionel Sambuc 
114*f4a2713aSLionel Sambuc     struct Inner
115*f4a2713aSLionel Sambuc     {
116*f4a2713aSLionel Sambuc       const Outer& o;
117*f4a2713aSLionel Sambuc 
118*f4a2713aSLionel Sambuc       template< class X >
operator XPR6021::Outer::Inner119*f4a2713aSLionel Sambuc       operator X() const
120*f4a2713aSLionel Sambuc       {
121*f4a2713aSLionel Sambuc         return o.tmpl<X>();
122*f4a2713aSLionel Sambuc       }
123*f4a2713aSLionel Sambuc     };
124*f4a2713aSLionel Sambuc   };
125*f4a2713aSLionel Sambuc }
126*f4a2713aSLionel Sambuc 
127*f4a2713aSLionel Sambuc namespace rdar8198511 {
128*f4a2713aSLionel Sambuc   template<int, typename U>
129*f4a2713aSLionel Sambuc   struct Base {
130*f4a2713aSLionel Sambuc     void f();
131*f4a2713aSLionel Sambuc   };
132*f4a2713aSLionel Sambuc 
133*f4a2713aSLionel Sambuc   template<typename T>
134*f4a2713aSLionel Sambuc   struct X0 : Base<1, T> { };
135*f4a2713aSLionel Sambuc 
136*f4a2713aSLionel Sambuc   template<typename T>
137*f4a2713aSLionel Sambuc   struct X1 {
138*f4a2713aSLionel Sambuc     X0<int> x0;
139*f4a2713aSLionel Sambuc 
frdar8198511::X1140*f4a2713aSLionel Sambuc     void f() {
141*f4a2713aSLionel Sambuc       this->x0.Base<1, int>::f();
142*f4a2713aSLionel Sambuc     }
143*f4a2713aSLionel Sambuc   };
144*f4a2713aSLionel Sambuc }
145