blob: c4a84472769144bcea52c748f82ec3e86154ebd3 [file] [log] [blame]
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001// Header for PCH test cxx-templates.cpp
2
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00003template <typename T1, typename T2>
Argyrios Kyrtzidis746c8892010-07-02 11:55:48 +00004struct S;
5
6template <typename T1, typename T2>
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00007struct S {
Argyrios Kyrtzidis746c8892010-07-02 11:55:48 +00008 S() { }
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00009 static void templ();
10};
11
12template <typename T>
13struct S<int, T> {
14 static void partial();
15};
16
17template <>
18struct S<int, float> {
19 static void explicit_special();
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +000020};
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000021
Argyrios Kyrtzidisddf5f212010-06-28 09:31:42 +000022template <int x>
23int tmpl_f2() { return x; }
24
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +000025template <typename T, int y>
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000026T templ_f(T x) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +000027 int z = templ_f<int, 5>(3);
Argyrios Kyrtzidisddf5f212010-06-28 09:31:42 +000028 z = tmpl_f2<y+2>();
Argyrios Kyrtzidis4a57bd02010-06-30 08:49:25 +000029 T data[y];
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +000030 return x+y;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000031}
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +000032
Argyrios Kyrtzidis58e01ad2010-06-25 09:03:34 +000033void govl(int);
34void govl(char);
35
36template <typename T>
37struct Unresolv {
38 void f() {
39 govl(T());
40 }
41};
42
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +000043template <typename T>
44struct Dep {
45 typedef typename T::type Ty;
46 void f() {
47 Ty x = Ty();
48 T::my_f();
49 int y = T::template my_templf<int>(0);
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +000050 ovl(y);
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +000051 }
Argyrios Kyrtzidisb8d3c632010-06-25 09:03:26 +000052
53 void ovl(int);
54 void ovl(float);
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +000055};
56
57template<typename T, typename A1>
58inline T make_a(const A1& a1) {
Argyrios Kyrtzidiscd444d1a2010-06-28 09:31:56 +000059 T::depend_declref();
Argyrios Kyrtzidisbfcacee2010-06-24 08:57:31 +000060 return T(a1);
61}
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000062
63template <class T> class UseBase {
64 void foo();
65 typedef int bar;
66};
67
68template <class T> class UseA : public UseBase<T> {
69 using UseBase<T>::foo;
70 using typename UseBase<T>::bar;
71};
Argyrios Kyrtzidis746c8892010-07-02 11:55:48 +000072
73template <class T> class Sub : public UseBase<int> { };
74
75template <class _Ret, class _Tp>
76 class mem_fun_t
77 {
78 public:
79 explicit
80 mem_fun_t(_Ret (_Tp::*__pf)())
81 {}
82
83 private:
84 _Ret (_Tp::*_M_f)();
85 };
86
87template<unsigned N>
88bool isInt(int x);
89
90template<> bool isInt<8>(int x) {
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +000091 try { ++x; } catch(...) { --x; }
92 return true;
Argyrios Kyrtzidis746c8892010-07-02 11:55:48 +000093}
94
95template<typename _CharT>
96int __copy_streambufs_eof(_CharT);
97
98class basic_streambuf
99{
100 void m() { }
101 friend int __copy_streambufs_eof<>(int);
102};
103
Argyrios Kyrtzidis3816ed42010-07-19 10:14:41 +0000104// PR 7660
105template<typename T> struct S_PR7660 { void g(void (*)(T)); };
106 template<> void S_PR7660<int>::g(void(*)(int)) {}
Argyrios Kyrtzidis47470f22010-07-20 13:59:28 +0000107
108// PR 7670
109template<typename> class C_PR7670;
110template<> class C_PR7670<int>;
111template<> class C_PR7670<int>;
Argyrios Kyrtzidis6e03a742010-07-29 20:07:52 +0000112
113template <bool B>
114struct S2 {
115 static bool V;
116};
117
118extern template class S2<true>;
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000119
120template <typename T>
121struct S3 {
122 void m();
123};
124
125template <typename T>
126inline void S3<T>::m() { }
Argyrios Kyrtzidis7f76d112010-08-05 09:48:16 +0000127
128template <typename T>
129struct S4 {
130 void m() { }
131};
132extern template struct S4<int>;
133
134void S4ImplicitInst() {
135 S4<int> s;
136 s.m();
137}
Argyrios Kyrtzidisd05f3e32010-09-06 19:04:27 +0000138
139struct S5 {
140 S5(int x);
141};
142
143struct TS5 {
144 S5 s;
145 template <typename T>
146 TS5(T y) : s(y) {}
147};
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000148
149// PR 8134
150template<class T> void f_PR8134(T);
151template<class T> void f_PR8134(T);
152void g_PR8134() { f_PR8134(0); f_PR8134('x'); }
Douglas Gregorf86c9392010-10-26 00:51:02 +0000153
154// rdar8580149
155template <typename T>
156struct S6;
157
158template <typename T, unsigned N>
159struct S6<const T [N]>
160{
161private:
162 typedef const T t1[N];
163public:
164 typedef t1& t2;
165};
166
Douglas Gregord4c5ed02010-10-29 22:39:52 +0000167template<typename T>
168 struct S7;
169
170template<unsigned N>
171struct S7<int[N]> : S6<const int[N]> { };
Douglas Gregor87866ce2011-02-04 12:01:24 +0000172
173// Zero-length template argument lists
174namespace ZeroLengthExplicitTemplateArgs {
175 template<typename T> void h();
176
177 struct Y {
178 template<typename T> void f();
179 };
180
181 template<typename T>
182 void f(T *ptr) {
183 T::template g<>(17);
184 ptr->template g2<>(17);
185 h<T>();
186 h<int>();
187 Y y;
188 y.f<int>();
189 }
190
191 struct X {
192 template<typename T> static void g(T);
193 template<typename T> void g2(T);
194 };
195}
Douglas Gregor250ffb12011-03-05 01:35:54 +0000196
197namespace NonTypeTemplateParmContext {
198 template<typename T, int inlineCapacity = 0> class Vector { };
199
200 struct String {
201 template<int inlineCapacity>
202 static String adopt(Vector<char, inlineCapacity>&);
203 };
204
205 template<int inlineCapacity>
206 inline bool equalIgnoringNullity(const Vector<char, inlineCapacity>& a, const String& b) { return false; }
207}
Douglas Gregor9f218892012-03-26 15:52:37 +0000208
209// <rdar://problem/11112464>
210template< typename > class Foo;
211
212template< typename T >
213class Foo : protected T
214{
215 public:
216 Foo& operator=( const Foo& other );
217};
Richard Smithb15fe3a2012-09-12 00:56:43 +0000218
219template<typename...A> struct NestedExpansion {
220 template<typename...B> auto f(A...a, B...b) -> decltype(g(a + b...));
221};
222template struct NestedExpansion<char, char, char>;
Argyrios Kyrtzidis83a6e3b2013-02-16 00:48:59 +0000223
224namespace rdar13135282 {
225template < typename _Alloc >
226void foo(_Alloc = _Alloc());
227
228template < bool > class __pool;
229
230template < template < bool > class _PoolTp >
231struct __common_pool {
232 typedef _PoolTp < 0 > pool_type;
233};
234
235template < template < bool > class _PoolTp >
236struct __common_pool_base : __common_pool < _PoolTp > {};
237
238template < template < bool > class _PoolTp >
239struct A : __common_pool_base < _PoolTp > {};
240
241template < typename _Poolp = A < __pool > >
242struct __mt_alloc {
243 typedef typename _Poolp::pool_type __pool_type;
244 __mt_alloc() {
245 foo<__mt_alloc<> >();
246 }
247};
248}
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000249
250namespace PR13020 {
251template<typename T>
252void f() {
253 enum E {
254 enumerator
255 };
256
257 T t = enumerator;
258}
259
260template void f<int>();
261}
Richard Smith5205a8c2013-04-01 20:22:16 +0000262
263template<typename T> void doNotDeserialize() {}
264template<typename T> struct ContainsDoNotDeserialize {
265 static int doNotDeserialize;
266};
267template<typename T> struct ContainsDoNotDeserialize2 {
268 static void doNotDeserialize();
269};
270template<typename T> int ContainsDoNotDeserialize<T>::doNotDeserialize = 0;
271template<typename T> void ContainsDoNotDeserialize2<T>::doNotDeserialize() {}
Eli Friedmanf796cf12013-06-19 01:38:21 +0000272
273
274template<typename T> void DependentSpecializedFunc(T x) { x.foo(); }
275template<typename T> class DependentSpecializedFuncClass {
276 void foo() {}
277 friend void DependentSpecializedFunc<>(DependentSpecializedFuncClass);
278};
Richard Smith95d99302013-07-13 02:00:19 +0000279
280namespace cyclic_module_load {
281 // Reduced from a libc++ modules crasher.
282 namespace std {
283 template<class> class mask_array;
284 template<class> class valarray {
285 public:
286 valarray(const valarray &v);
287 };
288
289 class gslice {
290 valarray<int> x;
291 valarray<int> stride() const { return x; }
292 };
293
294 template<class> class mask_array {
295 template<class> friend class valarray;
296 };
297 }
298}
Richard Smith1c34fb72013-08-13 18:18:50 +0000299
300namespace local_extern {
301 template<typename T> int f() {
302 extern int arr[3];
303 {
304 extern T arr;
305 return sizeof(arr);
306 }
307 }
308 template<typename T> int g() {
309 extern int arr[3];
310 extern T arr;
311 return sizeof(arr);
312 }
313}
Dmitri Gribenkob353ee12013-12-19 02:05:20 +0000314
315namespace rdar15468709a {
316 template<typename> struct decay {};
317
318 template<typename FooParamTy> auto foo(FooParamTy fooParam) -> decltype(fooParam);
319 template<typename BarParamTy> auto bar(BarParamTy barParam) -> decay<decltype(barParam)>;
320
321 struct B {};
322
323 void crash() {
324 B some;
325 bar(some);
326 }
327}
328
329namespace rdar15468709b {
330 template<typename> struct decay {};
331
332 template<typename... Foos> int returnsInt(Foos... foos);
333
334 template<typename... FooParamTy> auto foo(FooParamTy... fooParam) -> decltype(returnsInt(fooParam...));
335 template<typename... BarParamTy> auto bar(BarParamTy... barParam) -> decay<decltype(returnsInt(barParam...))>;
336
337 struct B {};
338
339 void crash() {
340 B some;
341 bar(some);
342 }
343}
344
345namespace rdar15468709c {
346 template<typename> struct decay {};
347
348 template<class... Foos> int returnsInt(Foos... foos);
349
350 template<typename FooParamTy> void foo(FooParamTy fooParam) { decltype(fooParam) a; }
351 template<typename BarParamTy> auto bar(BarParamTy barParam) -> decay<decltype(barParam)>;
352
353 struct B {};
354
355 void crash() {
356 B some;
357 bar(some);
358 }
359}
360