instantiate-member-template.cpp
5.78 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<typename T>
struct X0 {
template<typename U> T f0(U);
template<typename U> U& f1(T*, U); // expected-error{{pointer to a reference}} \
// expected-note{{candidate}}
};
X0<int> x0i;
X0<void> x0v;
X0<int&> x0ir; // expected-note{{instantiation}}
void test_X0(int *ip, double *dp) {
X0<int> xi;
int i1 = xi.f0(ip);
double *&dpr = xi.f1(ip, dp);
xi.f1(dp, dp); // expected-error{{no matching}}
X0<void> xv;
double *&dpr2 = xv.f1(ip, dp);
}
template<typename T>
struct X1 {
template<typename U>
struct Inner0 {
U x;
T y; // expected-error{{void}}
};
template<typename U>
struct Inner1 {
U x; // expected-error{{void}}
T y;
};
template<typename U>
struct Inner2 {
struct SuperInner {
U z; // expected-error{{void}}
};
};
template<typename U>
struct Inner3 {
void f0(T t, U u) { // expected-note{{passing argument to parameter 't' here}}
(void)(t + u); // expected-error{{invalid operands}}
}
template<typename V>
V f1(T t, U u, V) {
return t + u; // expected-error{{cannot initialize return object}}
}
};
template<typename U>
struct Inner4;
};
template<typename T>
template<typename U>
struct X1<T>::Inner4 {
template<typename V>
V f2(T t, U u, V);
static U value;
};
template<typename T>
template<typename U>
U X1<T>::Inner4<U>::value; // expected-error{{reference variable}}
template<typename T>
template<typename U>
template<typename V>
V X1<T>::Inner4<U>::f2(T t, U u, V) {
return t + u; // expected-error{{cannot initialize return object}}
}
void test_X1(int *ip, int i, double *dp) {
X1<void>::Inner0<int> *xvip; // okay
X1<void>::Inner0<int> xvi; // expected-note{{instantiation}}
X1<int>::Inner1<void> *xivp; // okay
X1<int>::Inner1<void> xiv; // expected-note{{instantiation}}
X1<int>::Inner2<void>::SuperInner *xisivp; // okay
X1<int>::Inner2<void>::SuperInner xisiv; // expected-note{{instantiation}}
X1<int*>::Inner3<int> id3;
id3.f0(ip, i);
id3.f0(dp, i); // expected-error{{cannot initialize a parameter of type 'int *' with an lvalue of type 'double *'}}
id3.f1(ip, i, ip);
id3.f1(ip, i, dp); // expected-note{{instantiation}}
X1<int*>::Inner3<double*> id3b;
id3b.f0(ip, dp); // expected-note{{instantiation}}
X1<int*>::Inner4<int> id4;
id4.f2(ip, i, dp); // expected-note{{instantiation}}
X1<int*>::Inner4<int>::value = 17;
i = X1<int*>::Inner4<int&>::value; // expected-note{{instantiation}}
}
template<typename T>
struct X2 {
template<T *Ptr> // expected-error{{pointer to a reference}}
struct Inner;
template<T Value> // expected-error{{cannot have type 'float'}}
struct Inner2;
};
X2<int&> x2a; // expected-note{{instantiation}}
X2<float> x2b; // expected-note{{instantiation}}
namespace N0 {
template<typename T>
struct X0 { };
struct X1 {
template<typename T> void f(X0<T>& vals) { g(vals); }
template<typename T> void g(X0<T>& vals) { }
};
void test(X1 x1, X0<int> x0i, X0<long> x0l) {
x1.f(x0i);
x1.f(x0l);
}
}
namespace PR6239 {
template <typename T>
struct X0 {
class type {
typedef T E;
template <E e> // subsitute T for E and bug goes away
struct sfinae { };
template <class U>
typename sfinae<&U::operator=>::type test(int);
};
};
template <typename T>
struct X1 {
typedef T E;
template <E e> // subsitute T for E and bug goes away
struct sfinae { };
template <class U>
typename sfinae<&U::operator=>::type test(int);
};
}
namespace PR7587 {
template<typename> class X0;
template<typename> struct X1;
template<typename> class X2;
template<typename T> class X3
{
template<
template<typename> class TT,
typename U = typename X1<T>::type
>
struct Inner {
typedef X2<TT<typename X1<T>::type> > Type;
};
const typename Inner<X0>::Type minCoeff() const;
};
template<typename T> class X3<T*>
{
template<
template<typename> class TT,
typename U = typename X1<T>::type
>
struct Inner {
typedef X2<TT<typename X1<T>::type> > Type;
};
const typename Inner<X0>::Type minCoeff() const;
};
}
namespace PR7669 {
template<class> struct X {
template<class> struct Y {
template<int,class> struct Z;
template<int Dummy> struct Z<Dummy,int> {};
};
};
void a()
{
X<int>::Y<int>::Z<0,int>();
}
}
namespace PR8489 {
template <typename CT>
class C {
template<typename FT>
void F() {} // expected-note{{FT}}
};
void f() {
C<int> c;
c.F(); // expected-error{{no matching member function}}
}
}
namespace rdar8986308 {
template <bool> struct __static_assert_test;
template <> struct __static_assert_test<true> {};
template <unsigned> struct __static_assert_check {};
namespace std {
template <class _Tp, class _Up>
struct __has_rebind
{
private:
struct __two {char _; char __;};
template <class _Xp> static __two __test(...);
template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
public:
static const bool value = sizeof(__test<_Tp>(0)) == 1;
};
}
template <class T> struct B1 {};
template <class T>
struct B
{
template <class U> struct rebind {typedef B1<U> other;};
};
template <class T, class U> struct D1 {};
template <class T, class U>
struct D
{
template <class V> struct rebind {typedef D1<V, U> other;};
};
int main()
{
typedef __static_assert_check<sizeof(__static_assert_test<((std::__has_rebind<B<int>, double>::value))>)> __t64;
typedef __static_assert_check<sizeof(__static_assert_test<((std::__has_rebind<D<char, int>, double>::value))>)> __t64;
}
}