2010-06-20 03:28:53 +08:00
|
|
|
// Header for PCH test cxx-templates.cpp
|
|
|
|
|
2010-07-02 19:55:48 +08:00
|
|
|
template <typename T1, typename T2>
|
|
|
|
struct S;
|
|
|
|
|
2010-06-23 21:48:30 +08:00
|
|
|
template <typename T1, typename T2>
|
2010-06-20 03:28:53 +08:00
|
|
|
struct S {
|
2010-07-02 19:55:48 +08:00
|
|
|
S() { }
|
2010-06-23 21:48:30 +08:00
|
|
|
static void templ();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct S<int, T> {
|
|
|
|
static void partial();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct S<int, float> {
|
|
|
|
static void explicit_special();
|
2010-06-20 03:28:53 +08:00
|
|
|
};
|
2010-06-22 17:55:07 +08:00
|
|
|
|
2010-06-28 17:31:42 +08:00
|
|
|
template <int x>
|
|
|
|
int tmpl_f2() { return x; }
|
|
|
|
|
2010-06-26 00:25:09 +08:00
|
|
|
template <typename T, int y>
|
2010-06-22 17:55:07 +08:00
|
|
|
T templ_f(T x) {
|
2010-06-28 17:31:34 +08:00
|
|
|
int z = templ_f<int, 5>(3);
|
2010-06-28 17:31:42 +08:00
|
|
|
z = tmpl_f2<y+2>();
|
2010-06-30 16:49:25 +08:00
|
|
|
T data[y];
|
2010-06-26 00:25:09 +08:00
|
|
|
return x+y;
|
2010-06-22 17:55:07 +08:00
|
|
|
}
|
2010-06-24 16:57:31 +08:00
|
|
|
|
2010-06-25 17:03:34 +08:00
|
|
|
void govl(int);
|
|
|
|
void govl(char);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct Unresolv {
|
|
|
|
void f() {
|
|
|
|
govl(T());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-24 16:57:31 +08:00
|
|
|
template <typename T>
|
|
|
|
struct Dep {
|
|
|
|
typedef typename T::type Ty;
|
|
|
|
void f() {
|
|
|
|
Ty x = Ty();
|
|
|
|
T::my_f();
|
|
|
|
int y = T::template my_templf<int>(0);
|
2010-06-25 17:03:26 +08:00
|
|
|
ovl(y);
|
2010-06-24 16:57:31 +08:00
|
|
|
}
|
2010-06-25 17:03:26 +08:00
|
|
|
|
|
|
|
void ovl(int);
|
|
|
|
void ovl(float);
|
2010-06-24 16:57:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, typename A1>
|
|
|
|
inline T make_a(const A1& a1) {
|
2010-06-28 17:31:56 +08:00
|
|
|
T::depend_declref();
|
2010-06-24 16:57:31 +08:00
|
|
|
return T(a1);
|
|
|
|
}
|
2010-06-30 16:49:30 +08:00
|
|
|
|
|
|
|
template <class T> class UseBase {
|
|
|
|
void foo();
|
|
|
|
typedef int bar;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> class UseA : public UseBase<T> {
|
|
|
|
using UseBase<T>::foo;
|
|
|
|
using typename UseBase<T>::bar;
|
|
|
|
};
|
2010-07-02 19:55:48 +08:00
|
|
|
|
|
|
|
template <class T> class Sub : public UseBase<int> { };
|
|
|
|
|
|
|
|
template <class _Ret, class _Tp>
|
|
|
|
class mem_fun_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit
|
|
|
|
mem_fun_t(_Ret (_Tp::*__pf)())
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
|
|
|
_Ret (_Tp::*_M_f)();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<unsigned N>
|
|
|
|
bool isInt(int x);
|
|
|
|
|
|
|
|
template<> bool isInt<8>(int x) {
|
2010-07-23 00:03:56 +08:00
|
|
|
try { ++x; } catch(...) { --x; }
|
|
|
|
return true;
|
2010-07-02 19:55:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename _CharT>
|
|
|
|
int __copy_streambufs_eof(_CharT);
|
|
|
|
|
|
|
|
class basic_streambuf
|
|
|
|
{
|
|
|
|
void m() { }
|
|
|
|
friend int __copy_streambufs_eof<>(int);
|
|
|
|
};
|
|
|
|
|
2010-07-19 18:14:41 +08:00
|
|
|
// PR 7660
|
|
|
|
template<typename T> struct S_PR7660 { void g(void (*)(T)); };
|
|
|
|
template<> void S_PR7660<int>::g(void(*)(int)) {}
|
2010-07-20 21:59:28 +08:00
|
|
|
|
|
|
|
// PR 7670
|
|
|
|
template<typename> class C_PR7670;
|
|
|
|
template<> class C_PR7670<int>;
|
|
|
|
template<> class C_PR7670<int>;
|
2010-07-30 04:07:52 +08:00
|
|
|
|
|
|
|
template <bool B>
|
|
|
|
struct S2 {
|
|
|
|
static bool V;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern template class S2<true>;
|
2010-08-04 01:30:10 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct S3 {
|
|
|
|
void m();
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void S3<T>::m() { }
|
2010-08-05 17:48:16 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct S4 {
|
|
|
|
void m() { }
|
|
|
|
};
|
|
|
|
extern template struct S4<int>;
|
|
|
|
|
|
|
|
void S4ImplicitInst() {
|
|
|
|
S4<int> s;
|
|
|
|
s.m();
|
|
|
|
}
|
2010-09-07 03:04:27 +08:00
|
|
|
|
|
|
|
struct S5 {
|
|
|
|
S5(int x);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TS5 {
|
|
|
|
S5 s;
|
|
|
|
template <typename T>
|
|
|
|
TS5(T y) : s(y) {}
|
|
|
|
};
|
2010-09-13 19:45:48 +08:00
|
|
|
|
|
|
|
// PR 8134
|
|
|
|
template<class T> void f_PR8134(T);
|
|
|
|
template<class T> void f_PR8134(T);
|
|
|
|
void g_PR8134() { f_PR8134(0); f_PR8134('x'); }
|
2010-10-26 08:51:02 +08:00
|
|
|
|
|
|
|
// rdar8580149
|
|
|
|
template <typename T>
|
|
|
|
struct S6;
|
|
|
|
|
|
|
|
template <typename T, unsigned N>
|
|
|
|
struct S6<const T [N]>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef const T t1[N];
|
|
|
|
public:
|
|
|
|
typedef t1& t2;
|
|
|
|
};
|
|
|
|
|
2010-10-30 06:39:52 +08:00
|
|
|
template<typename T>
|
|
|
|
struct S7;
|
|
|
|
|
|
|
|
template<unsigned N>
|
|
|
|
struct S7<int[N]> : S6<const int[N]> { };
|
2011-02-04 20:01:24 +08:00
|
|
|
|
|
|
|
// Zero-length template argument lists
|
|
|
|
namespace ZeroLengthExplicitTemplateArgs {
|
|
|
|
template<typename T> void h();
|
|
|
|
|
|
|
|
struct Y {
|
|
|
|
template<typename T> void f();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void f(T *ptr) {
|
|
|
|
T::template g<>(17);
|
|
|
|
ptr->template g2<>(17);
|
|
|
|
h<T>();
|
|
|
|
h<int>();
|
|
|
|
Y y;
|
|
|
|
y.f<int>();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct X {
|
|
|
|
template<typename T> static void g(T);
|
|
|
|
template<typename T> void g2(T);
|
|
|
|
};
|
|
|
|
}
|
2011-03-05 09:35:54 +08:00
|
|
|
|
|
|
|
namespace NonTypeTemplateParmContext {
|
|
|
|
template<typename T, int inlineCapacity = 0> class Vector { };
|
|
|
|
|
|
|
|
struct String {
|
|
|
|
template<int inlineCapacity>
|
|
|
|
static String adopt(Vector<char, inlineCapacity>&);
|
|
|
|
};
|
|
|
|
|
|
|
|
template<int inlineCapacity>
|
|
|
|
inline bool equalIgnoringNullity(const Vector<char, inlineCapacity>& a, const String& b) { return false; }
|
|
|
|
}
|
2012-03-26 23:52:37 +08:00
|
|
|
|
|
|
|
// <rdar://problem/11112464>
|
|
|
|
template< typename > class Foo;
|
|
|
|
|
|
|
|
template< typename T >
|
|
|
|
class Foo : protected T
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Foo& operator=( const Foo& other );
|
|
|
|
};
|
2012-09-12 08:56:43 +08:00
|
|
|
|
|
|
|
template<typename...A> struct NestedExpansion {
|
|
|
|
template<typename...B> auto f(A...a, B...b) -> decltype(g(a + b...));
|
|
|
|
};
|
|
|
|
template struct NestedExpansion<char, char, char>;
|
2013-02-16 08:48:59 +08:00
|
|
|
|
|
|
|
namespace rdar13135282 {
|
|
|
|
template < typename _Alloc >
|
|
|
|
void foo(_Alloc = _Alloc());
|
|
|
|
|
|
|
|
template < bool > class __pool;
|
|
|
|
|
|
|
|
template < template < bool > class _PoolTp >
|
|
|
|
struct __common_pool {
|
|
|
|
typedef _PoolTp < 0 > pool_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template < template < bool > class _PoolTp >
|
|
|
|
struct __common_pool_base : __common_pool < _PoolTp > {};
|
|
|
|
|
|
|
|
template < template < bool > class _PoolTp >
|
|
|
|
struct A : __common_pool_base < _PoolTp > {};
|
|
|
|
|
|
|
|
template < typename _Poolp = A < __pool > >
|
|
|
|
struct __mt_alloc {
|
|
|
|
typedef typename _Poolp::pool_type __pool_type;
|
|
|
|
__mt_alloc() {
|
|
|
|
foo<__mt_alloc<> >();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2013-03-19 06:23:49 +08:00
|
|
|
|
|
|
|
namespace PR13020 {
|
|
|
|
template<typename T>
|
|
|
|
void f() {
|
|
|
|
enum E {
|
|
|
|
enumerator
|
|
|
|
};
|
|
|
|
|
|
|
|
T t = enumerator;
|
|
|
|
}
|
|
|
|
|
|
|
|
template void f<int>();
|
|
|
|
}
|
2013-04-02 04:22:16 +08:00
|
|
|
|
|
|
|
template<typename T> void doNotDeserialize() {}
|
|
|
|
template<typename T> struct ContainsDoNotDeserialize {
|
|
|
|
static int doNotDeserialize;
|
|
|
|
};
|
|
|
|
template<typename T> struct ContainsDoNotDeserialize2 {
|
|
|
|
static void doNotDeserialize();
|
|
|
|
};
|
|
|
|
template<typename T> int ContainsDoNotDeserialize<T>::doNotDeserialize = 0;
|
|
|
|
template<typename T> void ContainsDoNotDeserialize2<T>::doNotDeserialize() {}
|
2013-06-19 09:38:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
template<typename T> void DependentSpecializedFunc(T x) { x.foo(); }
|
|
|
|
template<typename T> class DependentSpecializedFuncClass {
|
|
|
|
void foo() {}
|
|
|
|
friend void DependentSpecializedFunc<>(DependentSpecializedFuncClass);
|
|
|
|
};
|
2013-07-13 10:00:19 +08:00
|
|
|
|
|
|
|
namespace cyclic_module_load {
|
|
|
|
// Reduced from a libc++ modules crasher.
|
|
|
|
namespace std {
|
|
|
|
template<class> class mask_array;
|
|
|
|
template<class> class valarray {
|
|
|
|
public:
|
|
|
|
valarray(const valarray &v);
|
|
|
|
};
|
|
|
|
|
|
|
|
class gslice {
|
|
|
|
valarray<int> x;
|
|
|
|
valarray<int> stride() const { return x; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class> class mask_array {
|
|
|
|
template<class> friend class valarray;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2013-08-14 02:18:50 +08:00
|
|
|
|
|
|
|
namespace local_extern {
|
|
|
|
template<typename T> int f() {
|
|
|
|
extern int arr[3];
|
|
|
|
{
|
|
|
|
extern T arr;
|
|
|
|
return sizeof(arr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template<typename T> int g() {
|
|
|
|
extern int arr[3];
|
|
|
|
extern T arr;
|
|
|
|
return sizeof(arr);
|
|
|
|
}
|
|
|
|
}
|
2013-12-19 10:05:20 +08:00
|
|
|
|
|
|
|
namespace rdar15468709a {
|
|
|
|
template<typename> struct decay {};
|
|
|
|
|
|
|
|
template<typename FooParamTy> auto foo(FooParamTy fooParam) -> decltype(fooParam);
|
|
|
|
template<typename BarParamTy> auto bar(BarParamTy barParam) -> decay<decltype(barParam)>;
|
|
|
|
|
|
|
|
struct B {};
|
|
|
|
|
|
|
|
void crash() {
|
|
|
|
B some;
|
|
|
|
bar(some);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace rdar15468709b {
|
|
|
|
template<typename> struct decay {};
|
|
|
|
|
|
|
|
template<typename... Foos> int returnsInt(Foos... foos);
|
|
|
|
|
|
|
|
template<typename... FooParamTy> auto foo(FooParamTy... fooParam) -> decltype(returnsInt(fooParam...));
|
|
|
|
template<typename... BarParamTy> auto bar(BarParamTy... barParam) -> decay<decltype(returnsInt(barParam...))>;
|
|
|
|
|
|
|
|
struct B {};
|
|
|
|
|
|
|
|
void crash() {
|
|
|
|
B some;
|
|
|
|
bar(some);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace rdar15468709c {
|
|
|
|
template<typename> struct decay {};
|
|
|
|
|
|
|
|
template<class... Foos> int returnsInt(Foos... foos);
|
|
|
|
|
|
|
|
template<typename FooParamTy> void foo(FooParamTy fooParam) { decltype(fooParam) a; }
|
|
|
|
template<typename BarParamTy> auto bar(BarParamTy barParam) -> decay<decltype(barParam)>;
|
|
|
|
|
|
|
|
struct B {};
|
|
|
|
|
|
|
|
void crash() {
|
|
|
|
B some;
|
|
|
|
bar(some);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-10 07:02:10 +08:00
|
|
|
namespace MemberSpecializationLocation {
|
|
|
|
template<typename T> struct A { static int n; };
|
|
|
|
}
|
2018-08-01 05:01:53 +08:00
|
|
|
|
|
|
|
// https://bugs.llvm.org/show_bug.cgi?id=34728
|
|
|
|
namespace PR34728 {
|
|
|
|
|
|
|
|
// case 1: defaulted `NonTypeTemplateParmDecl`, non-defaulted 2nd tpl param
|
|
|
|
template <int foo = 10, class T>
|
|
|
|
int func1(T const &);
|
|
|
|
|
|
|
|
template <int foo, class T>
|
|
|
|
int func1(T const &) {
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
// case 2: defaulted `TemplateTypeParmDecl`, non-defaulted 2nd tpl param
|
|
|
|
template <class A = int, class B>
|
|
|
|
A func2(B const &);
|
|
|
|
|
|
|
|
template <class A, class B>
|
|
|
|
A func2(B const &) {
|
|
|
|
return A(20.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// case 3: defaulted `TemplateTemplateParmDecl`, non-defaulted 2nd tpl param
|
|
|
|
template <class T>
|
|
|
|
struct Container { T const &item; };
|
|
|
|
|
|
|
|
template <template <class> class C = Container, class D>
|
|
|
|
C<D> func3(D const &);
|
|
|
|
|
|
|
|
template <template <class> class C, class D>
|
|
|
|
C<D> func3(D const &d) {
|
|
|
|
return Container<D>{d};
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end namespace PR34728
|
2019-05-02 08:49:14 +08:00
|
|
|
|
|
|
|
namespace ClassScopeExplicitSpecializations {
|
|
|
|
template<int> struct A {
|
|
|
|
template<int> constexpr int f() const { return 1; }
|
|
|
|
template<> constexpr int f<0>() const { return 2; }
|
|
|
|
};
|
2019-05-04 07:51:38 +08:00
|
|
|
|
2019-05-02 08:49:14 +08:00
|
|
|
template<> template<int> constexpr int A<0>::f() const { return 3; }
|
|
|
|
template<> template<> constexpr int A<0>::f<0>() const { return 4; }
|
2019-05-04 07:51:38 +08:00
|
|
|
template<> template<> constexpr int A<0>::f<1>() const { return 5; }
|
|
|
|
|
2019-05-02 08:49:14 +08:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Winstantiation-after-specialization"
|
|
|
|
template int A<2>::f<0>() const;
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
template int A<2>::f<1>() const;
|
|
|
|
extern template int A<3>::f<0>() const;
|
|
|
|
extern template int A<3>::f<1>() const;
|
2019-05-04 07:51:38 +08:00
|
|
|
|
|
|
|
template<int> struct B {
|
|
|
|
template<typename> static const int v = 1;
|
|
|
|
template<typename T> static const int v<T*> = 2;
|
|
|
|
template<> static const int v<int> = 3;
|
|
|
|
|
|
|
|
template<typename> static constexpr int w = 1;
|
|
|
|
template<typename T> static constexpr int w<T*> = 2;
|
|
|
|
template<> static constexpr int w<int> = 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> template<typename> constexpr int B<0>::v = 4;
|
|
|
|
template<> template<typename T> constexpr int B<0>::v<T*> = 5;
|
|
|
|
template<> template<typename T> constexpr int B<0>::v<T&> = 6;
|
|
|
|
// This is ill-formed: the initializer of v<int> is instantiated with the
|
|
|
|
// class.
|
|
|
|
//template<> template<> constexpr int B<0>::v<int> = 7;
|
|
|
|
template<> template<> constexpr int B<0>::v<float> = 8;
|
|
|
|
|
|
|
|
template<> template<typename> constexpr int B<0>::w = 4;
|
|
|
|
template<> template<typename T> constexpr int B<0>::w<T*> = 5;
|
|
|
|
template<> template<typename T> constexpr int B<0>::w<T&> = 6;
|
|
|
|
template<> template<> constexpr int B<0>::w<int> = 7;
|
|
|
|
template<> template<> constexpr int B<0>::w<float> = 8;
|
2019-05-02 08:49:14 +08:00
|
|
|
}
|
2019-06-07 07:24:15 +08:00
|
|
|
|
|
|
|
namespace DependentMemberExpr {
|
|
|
|
struct Base {
|
|
|
|
constexpr int setstate() { return 0; }
|
|
|
|
};
|
|
|
|
template<typename T> struct A : Base {
|
|
|
|
constexpr int f() { return Base::setstate(); }
|
|
|
|
};
|
|
|
|
}
|
2019-12-17 05:04:31 +08:00
|
|
|
|
|
|
|
namespace DependentTemplateName {
|
|
|
|
template <template <class> class Template>
|
|
|
|
struct TakesClassTemplate {};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
TakesClassTemplate<T::template Member> getWithIdentifier();
|
|
|
|
}
|