Clang Project

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