[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / PCH / cxx-templates.h
blob7819a1ecb8e1c0fbbb1e2276993b54da5b47ff6c
1 // Header for PCH test cxx-templates.cpp
3 template <typename T1, typename T2>
4 struct S;
6 template <typename T1, typename T2>
7 struct S {
8 S() { }
9 static void templ();
12 template <typename T>
13 struct S<int, T> {
14 static void partial();
17 template <>
18 struct S<int, float> {
19 static void explicit_special();
22 template <int x>
23 int tmpl_f2() { return x; }
25 template <typename T, int y>
26 T templ_f(T x) {
27 int z = templ_f<int, 5>(3);
28 z = tmpl_f2<y+2>();
29 T data[y];
30 return x+y;
33 void govl(int);
34 void govl(char);
36 template <typename T>
37 struct Unresolv {
38 void f() {
39 govl(T());
43 template <typename T>
44 struct 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);
50 ovl(y);
53 void ovl(int);
54 void ovl(float);
57 template<typename T, typename A1>
58 inline T make_a(const A1& a1) {
59 T::depend_declref();
60 return T(a1);
63 template <class T> class UseBase {
64 void foo();
65 typedef int bar;
68 template <class T> class UseA : public UseBase<T> {
69 using UseBase<T>::foo;
70 using typename UseBase<T>::bar;
73 template <class T> class Sub : public UseBase<int> { };
75 template <class _Ret, class _Tp>
76 class mem_fun_t
78 public:
79 explicit
80 mem_fun_t(_Ret (_Tp::*__pf)())
83 private:
84 _Ret (_Tp::*_M_f)();
87 template<unsigned N>
88 bool isInt(int x);
90 template<> bool isInt<8>(int x) {
91 try { ++x; } catch(...) { --x; }
92 return true;
95 template<typename _CharT>
96 int __copy_streambufs_eof(_CharT);
98 class basic_streambuf
100 void m() { }
101 friend int __copy_streambufs_eof<>(int);
104 // PR 7660
105 template<typename T> struct S_PR7660 { void g(void (*)(T)); };
106 template<> void S_PR7660<int>::g(void(*)(int)) {}
108 // PR 7670
109 template<typename> class C_PR7670;
110 template<> class C_PR7670<int>;
111 template<> class C_PR7670<int>;
113 template <bool B>
114 struct S2 {
115 static bool V;
118 extern template class S2<true>;
120 template <typename T>
121 struct S3 {
122 void m();
125 template <typename T>
126 inline void S3<T>::m() { }
128 template <typename T>
129 struct S4 {
130 void m() { }
132 extern template struct S4<int>;
134 void S4ImplicitInst() {
135 S4<int> s;
136 s.m();
139 struct S5 {
140 S5(int x);
143 struct TS5 {
144 S5 s;
145 template <typename T>
146 TS5(T y) : s(y) {}
149 // PR 8134
150 template<class T> void f_PR8134(T);
151 template<class T> void f_PR8134(T);
152 void g_PR8134() { f_PR8134(0); f_PR8134('x'); }
154 // rdar8580149
155 template <typename T>
156 struct S6;
158 template <typename T, unsigned N>
159 struct S6<const T [N]>
161 private:
162 typedef const T t1[N];
163 public:
164 typedef t1& t2;
167 template<typename T>
168 struct S7;
170 template<unsigned N>
171 struct S7<int[N]> : S6<const int[N]> { };
173 // Zero-length template argument lists
174 namespace ZeroLengthExplicitTemplateArgs {
175 template<typename T> void h();
177 struct Y {
178 template<typename T> void f();
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>();
191 struct X {
192 template<typename T> static void g(T);
193 template<typename T> void g2(T);
197 namespace NonTypeTemplateParmContext {
198 template<typename T, int inlineCapacity = 0> class Vector { };
200 struct String {
201 template<int inlineCapacity>
202 static String adopt(Vector<char, inlineCapacity>&);
205 template<int inlineCapacity>
206 inline bool equalIgnoringNullity(const Vector<char, inlineCapacity>& a, const String& b) { return false; }
209 // <rdar://problem/11112464>
210 template< typename > class Foo;
212 template< typename T >
213 class Foo : protected T
215 public:
216 Foo& operator=( const Foo& other );
219 template<typename...A> struct NestedExpansion {
220 template<typename...B> auto f(A...a, B...b) -> decltype(g(a + b...));
222 template struct NestedExpansion<char, char, char>;
224 namespace rdar13135282 {
225 template < typename _Alloc >
226 void foo(_Alloc = _Alloc());
228 template < bool > class __pool;
230 template < template < bool > class _PoolTp >
231 struct __common_pool {
232 typedef _PoolTp < 0 > pool_type;
235 template < template < bool > class _PoolTp >
236 struct __common_pool_base : __common_pool < _PoolTp > {};
238 template < template < bool > class _PoolTp >
239 struct A : __common_pool_base < _PoolTp > {};
241 template < typename _Poolp = A < __pool > >
242 struct __mt_alloc {
243 typedef typename _Poolp::pool_type __pool_type;
244 __mt_alloc() {
245 foo<__mt_alloc<> >();
250 namespace PR13020 {
251 template<typename T>
252 void f() {
253 enum E {
254 enumerator
257 T t = enumerator;
260 template void f<int>();
263 template<typename T> void doNotDeserialize() {}
264 template<typename T> struct ContainsDoNotDeserialize {
265 static int doNotDeserialize;
267 template<typename T> struct ContainsDoNotDeserialize2 {
268 static void doNotDeserialize();
270 template<typename T> int ContainsDoNotDeserialize<T>::doNotDeserialize = 0;
271 template<typename T> void ContainsDoNotDeserialize2<T>::doNotDeserialize() {}
274 template<typename T> void DependentSpecializedFunc(T x) { x.foo(); }
275 template<typename T> class DependentSpecializedFuncClass {
276 void foo() {}
277 friend void DependentSpecializedFunc<>(DependentSpecializedFuncClass);
280 namespace 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);
289 class gslice {
290 valarray<int> x;
291 valarray<int> stride() const { return x; }
294 template<class> class mask_array {
295 template<class> friend class valarray;
300 namespace local_extern {
301 template<typename T> int f() {
302 extern int arr[3];
304 extern T arr;
305 return sizeof(arr);
308 template<typename T> int g() {
309 extern int arr[3];
310 extern T arr;
311 return sizeof(arr);
315 namespace rdar15468709a {
316 template<typename> struct decay {};
318 template<typename FooParamTy> auto foo(FooParamTy fooParam) -> decltype(fooParam);
319 template<typename BarParamTy> auto bar(BarParamTy barParam) -> decay<decltype(barParam)>;
321 struct B {};
323 void crash() {
324 B some;
325 bar(some);
329 namespace rdar15468709b {
330 template<typename> struct decay {};
332 template<typename... Foos> int returnsInt(Foos... foos);
334 template<typename... FooParamTy> auto foo(FooParamTy... fooParam) -> decltype(returnsInt(fooParam...));
335 template<typename... BarParamTy> auto bar(BarParamTy... barParam) -> decay<decltype(returnsInt(barParam...))>;
337 struct B {};
339 void crash() {
340 B some;
341 bar(some);
345 namespace rdar15468709c {
346 template<typename> struct decay {};
348 template<class... Foos> int returnsInt(Foos... foos);
350 template<typename FooParamTy> void foo(FooParamTy fooParam) { decltype(fooParam) a; }
351 template<typename BarParamTy> auto bar(BarParamTy barParam) -> decay<decltype(barParam)>;
353 struct B {};
355 void crash() {
356 B some;
357 bar(some);
361 namespace MemberSpecializationLocation {
362 template<typename T> struct A { static int n; };
365 // https://bugs.llvm.org/show_bug.cgi?id=34728
366 namespace PR34728 {
368 // case 1: defaulted `NonTypeTemplateParmDecl`, non-defaulted 2nd tpl param
369 template <int foo = 10, class T>
370 int func1(T const &);
372 template <int foo, class T>
373 int func1(T const &) {
374 return foo;
377 // case 2: defaulted `TemplateTypeParmDecl`, non-defaulted 2nd tpl param
378 template <class A = int, class B>
379 A func2(B const &);
381 template <class A, class B>
382 A func2(B const &) {
383 return A(20.0f);
386 // case 3: defaulted `TemplateTemplateParmDecl`, non-defaulted 2nd tpl param
387 template <class T>
388 struct Container { T const &item; };
390 template <template <class> class C = Container, class D>
391 C<D> func3(D const &);
393 template <template <class> class C, class D>
394 C<D> func3(D const &d) {
395 return Container<D>{d};
398 } // end namespace PR34728
400 namespace ClassScopeExplicitSpecializations {
401 template<int> struct A {
402 template<int> constexpr int f() const { return 1; }
403 template<> constexpr int f<0>() const { return 2; }
406 template<> template<int> constexpr int A<0>::f() const { return 3; }
407 template<> template<> constexpr int A<0>::f<0>() const { return 4; }
408 template<> template<> constexpr int A<0>::f<1>() const { return 5; }
410 #pragma clang diagnostic push
411 #pragma clang diagnostic ignored "-Winstantiation-after-specialization"
412 template int A<2>::f<0>() const;
413 #pragma clang diagnostic pop
414 template int A<2>::f<1>() const;
415 extern template int A<3>::f<0>() const;
416 extern template int A<3>::f<1>() const;
418 template<int> struct B {
419 template<typename> static const int v = 1;
420 template<typename T> static const int v<T*> = 2;
421 template<> static const int v<int> = 3;
423 template<typename> static constexpr int w = 1;
424 template<typename T> static constexpr int w<T*> = 2;
425 template<> static constexpr int w<int> = 3;
428 template<> template<typename> constexpr int B<0>::v = 4;
429 template<> template<typename T> constexpr int B<0>::v<T*> = 5;
430 template<> template<typename T> constexpr int B<0>::v<T&> = 6;
431 // This is ill-formed: the initializer of v<int> is instantiated with the
432 // class.
433 //template<> template<> constexpr int B<0>::v<int> = 7;
434 template<> template<> constexpr int B<0>::v<float> = 8;
436 template<> template<typename> constexpr int B<0>::w = 4;
437 template<> template<typename T> constexpr int B<0>::w<T*> = 5;
438 template<> template<typename T> constexpr int B<0>::w<T&> = 6;
439 template<> template<> constexpr int B<0>::w<int> = 7;
440 template<> template<> constexpr int B<0>::w<float> = 8;
443 namespace DependentMemberExpr {
444 struct Base {
445 constexpr int setstate() { return 0; }
447 template<typename T> struct A : Base {
448 constexpr int f() { return Base::setstate(); }
452 namespace DependentTemplateName {
453 template <template <class> class Template>
454 struct TakesClassTemplate {};
456 template <class T>
457 TakesClassTemplate<T::template Member> getWithIdentifier();
460 namespace ClassTemplateCycle {
461 // Create a cycle: the typedef T refers to A<0, 8>, whose template argument
462 // list refers back to T.
463 template<int, int> struct A;
464 using T = A<0, sizeof(void*)>;
465 template<int N> struct A<N, sizeof(T*)> {};
466 T t;
468 // Create a cycle: the variable M refers to A<1, 1>, whose template argument
469 // list list refers back to M.
470 template<int, int> struct A;
471 const decltype(sizeof(A<1, 1>*)) M = 1;
472 template<int N> struct A<N, M> {};
473 A<1, 1> u;