1 // REQUIRES: x86-registered-target 2 // RUN: %clang_cc1 %s -S -triple=x86_64 -mllvm -sort-timers=0 -o - -ftime-report 2>&1 | FileCheck %s 3 // RUN: %clang_cc1 %s -S -triple=x86_64 -mllvm -sort-timers=0 -o - -fdelayed-template-parsing -DDELAYED_TEMPLATE_PARSING -ftime-report 2>&1 | FileCheck %s 4 5 // Template function declarations 6 template <typename T> 7 void foo(); 8 template <typename T, typename U> 9 void foo(); 10 11 // Template function definitions. 12 template <typename T> 13 void foo() {} 14 15 // Template class (forward) declarations 16 template <typename T> 17 struct A; 18 template <typename T, typename U> 19 struct b; 20 template <typename> 21 struct C; 22 template <typename, typename> 23 struct D; 24 25 // Forward declarations with default parameters? 26 template <typename T = int> 27 class X1; 28 template <typename = int> 29 class X2; 30 31 // Forward declarations w/template template parameters 32 template <template <typename> class T> 33 class TTP1; 34 template <template <typename> class> 35 class TTP2; 36 template <template <typename X, typename Y> class T> 37 class TTP5; 38 39 // Forward declarations with non-type params 40 template <int> 41 class NTP0; 42 template <int N> 43 class NTP1; 44 template <int N = 5> 45 class NTP2; 46 template <int = 10> 47 class NTP3; 48 template <unsigned int N = 12u> 49 class NTP4; 50 template <unsigned int = 12u> 51 class NTP5; 52 template <unsigned = 15u> 53 class NTP6; 54 template <typename T, T Obj> 55 class NTP7; 56 57 // Template class declarations 58 template <typename T> 59 struct A {}; 60 template <typename T, typename U> 61 struct B {}; 62 63 namespace PR6184 { 64 namespace N { 65 template <typename T> 66 void bar(typename T::x); 67 } 68 69 template <typename T> 70 void N::bar(typename T::x) {} 71 } 72 73 // This PR occurred only in template parsing mode. 74 namespace PR17637 { 75 template <int> 76 struct L { 77 template <typename T> 78 struct O { 79 template <typename U> 80 static void Fun(U); 81 }; 82 }; 83 84 template <int k> 85 template <typename T> 86 template <typename U> 87 void L<k>::O<T>::Fun(U) {} 88 89 void Instantiate() { L<0>::O<int>::Fun(0); } 90 } 91 92 namespace explicit_partial_specializations { 93 typedef char (&oneT)[1]; 94 typedef char (&twoT)[2]; 95 typedef char (&threeT)[3]; 96 typedef char (&fourT)[4]; 97 typedef char (&fiveT)[5]; 98 typedef char (&sixT)[6]; 99 100 char one[1]; 101 char two[2]; 102 char three[3]; 103 char four[4]; 104 char five[5]; 105 char six[6]; 106 107 template <bool b> 108 struct bool_ { typedef int type; }; 109 template <> 110 struct bool_<false> {}; 111 112 #define XCAT(x, y) x##y 113 #define CAT(x, y) XCAT(x, y) 114 #define sassert(_b_) bool_<(_b_)>::type CAT(var, __LINE__); 115 116 template <int> 117 struct L { 118 template <typename T> 119 struct O { 120 template <typename U> 121 static oneT Fun(U); 122 }; 123 }; 124 template <int k> 125 template <typename T> 126 template <typename U> 127 oneT L<k>::O<T>::Fun(U) { return one; } 128 129 template <> 130 template <> 131 template <typename U> 132 oneT L<0>::O<char>::Fun(U) { return one; } 133 134 void Instantiate() { 135 sassert(sizeof(L<0>::O<int>::Fun(0)) == sizeof(one)); 136 sassert(sizeof(L<0>::O<char>::Fun(0)) == sizeof(one)); 137 } 138 } 139 140 template <class> 141 struct Foo { 142 template <class _Other> 143 using rebind_alloc = _Other; 144 }; 145 template <class _Alloc> 146 struct _Wrap_alloc { 147 template <class _Other> 148 using rebind_alloc = typename Foo<_Alloc>::template rebind_alloc<_Other>; 149 template <class> 150 using rebind = _Wrap_alloc; 151 }; 152 _Wrap_alloc<int>::rebind<int> w; 153 154 // CHECK: Clang time report 155 // CHECK: Front end 156 // CHECK-NEXT: LLVM IR generation 157 // CHECK-NEXT: Machine code generation 158 // CHECK-NEXT: Optimizer 159 // CHECK-NEXT: Total 160