xref: /llvm-project/clang/test/SemaTemplate/member-template-access-expr.cpp (revision d33198420ddad07a08e42730d9e4245bcf7f12a7)
1 // RUN: clang-cc -fsyntax-only -verify %s
2 template<typename U, typename T>
3 U f0(T t) {
4   return t.template get<U>();
5 }
6 
7 template<typename U, typename T>
8 int &f1(T t) {
9   // FIXME: When we pretty-print this, we lose the "template" keyword.
10   return t.U::template get<int&>();
11 }
12 
13 struct X {
14   template<typename T> T get();
15 };
16 
17 void test_f0(X x) {
18   int i = f0<int>(x);
19   int &ir = f0<int&>(x);
20 }
21 
22 struct XDerived : public X {
23 };
24 
25 void test_f1(XDerived xd) {
26   int &ir = f1<X>(xd);
27 }
28 
29 // PR5213
30 template <class T>
31 struct A {};
32 
33 template<class T>
34 class B
35 {
36   A<T> a_;
37 
38 public:
39   void destroy();
40 };
41 
42 template<class T>
43 void
44 B<T>::destroy()
45 {
46   a_.~A<T>();
47 }
48 
49 void do_destroy_B(B<int> b) {
50   b.destroy();
51 }
52 
53 struct X1 {
54   int* f1(int);
55   template<typename T> float* f1(T);
56 
57   static int* f2(int);
58   template<typename T> static float* f2(T);
59 };
60 
61 void test_X1(X1 x1) {
62   float *fp1 = x1.f1<>(17);
63   float *fp2 = x1.f1<int>(3.14);
64   int *ip1 = x1.f1(17);
65   float *ip2 = x1.f1(3.14);
66 
67   float* (X1::*mf1)(int) = &X1::f1;
68   float* (X1::*mf2)(int) = &X1::f1<>;
69   float* (X1::*mf3)(float) = &X1::f1<float>;
70 
71   float* (*fp3)(int) = &X1::f2;
72   float* (*fp4)(int) = &X1::f2<>;
73   float* (*fp5)(float) = &X1::f2<float>;
74   float* (*fp6)(int) = X1::f2;
75   float* (*fp7)(int) = X1::f2<>;
76   float* (*fp8)(float) = X1::f2<float>;
77 }
78