summaryrefslogtreecommitdiffstats
path: root/test/SemaTemplate/member-template-access-expr.cpp
blob: c95b57d4b4fddedd66e17d9f63c75d09125d4524 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename U, typename T>
U f0(T t) {
  return t.template get<U>();
}

template<typename U, typename T>
int &f1(T t) {
  // FIXME: When we pretty-print this, we lose the "template" keyword.
  return t.U::template get<int&>();
}

struct X {
  template<typename T> T get();
};

void test_f0(X x) {
  int i = f0<int>(x);
  int &ir = f0<int&>(x);
}

struct XDerived : public X {
};

void test_f1(XDerived xd) {
  int &ir = f1<X>(xd);
}

// PR5213
template <class T>
struct A {};

template<class T>
class B
{
  A<T> a_;
  
public:
  void destroy();
};

template<class T>
void
B<T>::destroy()
{
  a_.~A<T>();
}

void do_destroy_B(B<int> b) {
  b.destroy();
}

struct X1 {
  int* f1(int);
  template<typename T> float* f1(T);
  
  static int* f2(int);
  template<typename T> static float* f2(T);
};

void test_X1(X1 x1) {
  float *fp1 = x1.f1<>(17);
  float *fp2 = x1.f1<int>(3.14); // expected-warning {{implicit conversion turns literal floating-point number into integer}}
  int *ip1 = x1.f1(17);
  float *ip2 = x1.f1(3.14);
  
  float* (X1::*mf1)(int) = &X1::f1;
  float* (X1::*mf2)(int) = &X1::f1<>;
  float* (X1::*mf3)(float) = &X1::f1<float>;
  
  float* (*fp3)(int) = &X1::f2;
  float* (*fp4)(int) = &X1::f2<>;
  float* (*fp5)(float) = &X1::f2<float>;  
  float* (*fp6)(int) = X1::f2;
  float* (*fp7)(int) = X1::f2<>;
  float* (*fp8)(float) = X1::f2<float>;  
}

template<int A> struct X2 { 
  int m;
};

template<typename T>
struct X3 : T { };

template<typename T>
struct X4 {
  template<typename U>
  void f(X2<sizeof(X3<U>().U::m)>);
};

void f(X4<X3<int> > x4i) {
  X2<sizeof(int)> x2;
  x4i.f<X2<sizeof(int)> >(x2);
}

template<typename T>
struct X5 {
  template<typename U>
  void f();
  
  void g() {
    this->f<T*>();
  }
};

namespace PR6021 {
  template< class T1, class T2 >
  class Outer
  {
  public: // Range operations
    template< class X > X tmpl( const X* = 0 ) const;

    struct Inner
    {
      const Outer& o;

      template< class X >
      operator X() const
      {
        return o.tmpl<X>();
      }
    };
  };
}

namespace rdar8198511 {
  template<int, typename U>
  struct Base { 
    void f();
  };

  template<typename T>
  struct X0 : Base<1, T> { };

  template<typename T>
  struct X1 {
    X0<int> x0;

    void f() {
      this->x0.Base<1, int>::f();
    }
  };
}