1// Header for PCH test cxx-templates.cpp 2 3template <typename T1, typename T2> 4struct S; 5 6template <typename T1, typename T2> 7struct S { 8 S() { } 9 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(); 20}; 21 22template <int x> 23int tmpl_f2() { return x; } 24 25template <typename T, int y> 26T 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; 31} 32 33void govl(int); 34void govl(char); 35 36template <typename T> 37struct Unresolv { 38 void f() { 39 govl(T()); 40 } 41}; 42 43template <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); 50 ovl(y); 51 } 52 53 void ovl(int); 54 void ovl(float); 55}; 56 57template<typename T, typename A1> 58inline T make_a(const A1& a1) { 59 T::depend_declref(); 60 return T(a1); 61} 62 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}; 72 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) { 91 try { ++x; } catch(...) { --x; } 92 return true; 93} 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 104// PR 7660 105template<typename T> struct S_PR7660 { void g(void (*)(T)); }; 106 template<> void S_PR7660<int>::g(void(*)(int)) {} 107 108// PR 7670 109template<typename> class C_PR7670; 110template<> class C_PR7670<int>; 111template<> class C_PR7670<int>; 112 113template <bool B> 114struct S2 { 115 static bool V; 116}; 117 118extern template class S2<true>; 119 120template <typename T> 121struct S3 { 122 void m(); 123}; 124 125template <typename T> 126inline void S3<T>::m() { } 127 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} 138 139struct S5 { 140 S5(int x); 141}; 142 143struct TS5 { 144 S5 s; 145 template <typename T> 146 TS5(T y) : s(y) {} 147}; 148 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'); } 153 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 167template<typename T> 168 struct S7; 169 170template<unsigned N> 171struct S7<int[N]> : S6<const int[N]> { }; 172 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} 196 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} 208 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}; 218 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>; 223 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} 249 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} 262 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() {} 272 273 274template<typename T> void DependentSpecializedFunc(T x) { x.foo(); } 275template<typename T> class DependentSpecializedFuncClass { 276 void foo() {} 277 friend void DependentSpecializedFunc<>(DependentSpecializedFuncClass); 278}; 279 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} 299 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} 314 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 361