1 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s
2 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s
3
4 template<typename T>
5 class Class {
6 public:
Class()7 Class() {}
8 };
9
10 class Typename { };
11
12 template<typename T>
13 class Nested { };
14
15 template<bool flag>
16 class BoolTemplate {
17 public:
BoolTemplate()18 BoolTemplate() {}
19 };
20
21 template<int param>
22 class IntTemplate {
23 public:
IntTemplate()24 IntTemplate() {}
25 };
26
27 template<long long param>
28 class LongLongTemplate {
29 public:
LongLongTemplate()30 LongLongTemplate() {}
31 };
32
33 template<unsigned long long param>
34 class UnsignedLongLongTemplate {
35 public:
UnsignedLongLongTemplate()36 UnsignedLongLongTemplate() {}
37 };
38
39 template<>
40 class BoolTemplate<true> {
41 public:
BoolTemplate()42 BoolTemplate() {}
Foo(T arg)43 template<class T> void Foo(T arg) {}
44 };
45
template_mangling()46 void template_mangling() {
47 Class<Typename> c1;
48 // CHECK: call {{.*}} @"\01??0?$Class@VTypename@@@@QAE@XZ"
49 // X64: call {{.*}} @"\01??0?$Class@VTypename@@@@QEAA@XZ"
50
51 Class<const Typename> c1_const;
52 // CHECK: call {{.*}} @"\01??0?$Class@$$CBVTypename@@@@QAE@XZ"
53 // X64: call {{.*}} @"\01??0?$Class@$$CBVTypename@@@@QEAA@XZ"
54 Class<volatile Typename> c1_volatile;
55 // CHECK: call {{.*}} @"\01??0?$Class@$$CCVTypename@@@@QAE@XZ"
56 // X64: call {{.*}} @"\01??0?$Class@$$CCVTypename@@@@QEAA@XZ"
57 Class<const volatile Typename> c1_cv;
58 // CHECK: call {{.*}} @"\01??0?$Class@$$CDVTypename@@@@QAE@XZ"
59 // X64: call {{.*}} @"\01??0?$Class@$$CDVTypename@@@@QEAA@XZ"
60
61 Class<Nested<Typename> > c2;
62 // CHECK: call {{.*}} @"\01??0?$Class@V?$Nested@VTypename@@@@@@QAE@XZ"
63 // X64: call {{.*}} @"\01??0?$Class@V?$Nested@VTypename@@@@@@QEAA@XZ"
64
65 Class<int * const> c_intpc;
66 // CHECK: call {{.*}} @"\01??0?$Class@QAH@@QAE@XZ"
67 // X64: call {{.*}} @"\01??0?$Class@QEAH@@QEAA@XZ"
68 Class<int()> c_ft;
69 // CHECK: call {{.*}} @"\01??0?$Class@$$A6AHXZ@@QAE@XZ"
70 // X64: call {{.*}} @"\01??0?$Class@$$A6AHXZ@@QEAA@XZ"
71 Class<int[]> c_inti;
72 // CHECK: call {{.*}} @"\01??0?$Class@$$BY0A@H@@QAE@XZ"
73 // X64: call {{.*}} @"\01??0?$Class@$$BY0A@H@@QEAA@XZ"
74 Class<int[5]> c_int5;
75 // CHECK: call {{.*}} @"\01??0?$Class@$$BY04H@@QAE@XZ"
76 // X64: call {{.*}} @"\01??0?$Class@$$BY04H@@QEAA@XZ"
77 Class<const int[5]> c_intc5;
78 // CHECK: call {{.*}} @"\01??0?$Class@$$BY04$$CBH@@QAE@XZ"
79 // X64: call {{.*}} @"\01??0?$Class@$$BY04$$CBH@@QEAA@XZ"
80 Class<int * const[5]> c_intpc5;
81 // CHECK: call {{.*}} @"\01??0?$Class@$$BY04QAH@@QAE@XZ"
82 // X64: call {{.*}} @"\01??0?$Class@$$BY04QEAH@@QEAA@XZ"
83
84 BoolTemplate<false> _false;
85 // CHECK: call {{.*}} @"\01??0?$BoolTemplate@$0A@@@QAE@XZ"
86 // X64: call {{.*}} @"\01??0?$BoolTemplate@$0A@@@QEAA@XZ"
87
88 BoolTemplate<true> _true;
89 // PR13158
90 _true.Foo(1);
91 // CHECK: call {{.*}} @"\01??0?$BoolTemplate@$00@@QAE@XZ"
92 // X64: call {{.*}} @"\01??0?$BoolTemplate@$00@@QEAA@XZ"
93 // CHECK: call {{.*}} @"\01??$Foo@H@?$BoolTemplate@$00@@QAEXH@Z"
94 // X64: call {{.*}} @"\01??$Foo@H@?$BoolTemplate@$00@@QEAAXH@Z"
95
96 IntTemplate<0> zero;
97 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0A@@@QAE@XZ"
98 // X64: call {{.*}} @"\01??0?$IntTemplate@$0A@@@QEAA@XZ"
99
100 IntTemplate<5> five;
101 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$04@@QAE@XZ"
102 // X64: call {{.*}} @"\01??0?$IntTemplate@$04@@QEAA@XZ"
103
104 IntTemplate<11> eleven;
105 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0L@@@QAE@XZ"
106 // X64: call {{.*}} @"\01??0?$IntTemplate@$0L@@@QEAA@XZ"
107
108 IntTemplate<256> _256;
109 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0BAA@@@QAE@XZ"
110 // X64: call {{.*}} @"\01??0?$IntTemplate@$0BAA@@@QEAA@XZ"
111
112 IntTemplate<513> _513;
113 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0CAB@@@QAE@XZ"
114 // X64: call {{.*}} @"\01??0?$IntTemplate@$0CAB@@@QEAA@XZ"
115
116 IntTemplate<1026> _1026;
117 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0EAC@@@QAE@XZ"
118 // X64: call {{.*}} @"\01??0?$IntTemplate@$0EAC@@@QEAA@XZ"
119
120 IntTemplate<65535> ffff;
121 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0PPPP@@@QAE@XZ"
122 // X64: call {{.*}} @"\01??0?$IntTemplate@$0PPPP@@@QEAA@XZ"
123
124 IntTemplate<-1> neg_1;
125 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?0@@QAE@XZ"
126 // X64: call {{.*}} @"\01??0?$IntTemplate@$0?0@@QEAA@XZ"
127 IntTemplate<-9> neg_9;
128 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?8@@QAE@XZ"
129 // X64: call {{.*}} @"\01??0?$IntTemplate@$0?8@@QEAA@XZ"
130 IntTemplate<-10> neg_10;
131 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?9@@QAE@XZ"
132 // X64: call {{.*}} @"\01??0?$IntTemplate@$0?9@@QEAA@XZ"
133 IntTemplate<-11> neg_11;
134 // CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?L@@@QAE@XZ"
135 // X64: call {{.*}} @"\01??0?$IntTemplate@$0?L@@@QEAA@XZ"
136
137 LongLongTemplate<-9223372036854775807LL-1LL> int64_min;
138 // CHECK: call {{.*}} @"\01??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QAE@XZ"
139 // X64: call {{.*}} @"\01??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QEAA@XZ"
140 LongLongTemplate<9223372036854775807LL> int64_max;
141 // CHECK: call {{.*}} @"\01??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QAE@XZ"
142 // X64: call {{.*}} @"\01??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QEAA@XZ"
143 UnsignedLongLongTemplate<18446744073709551615ULL> uint64_max;
144 // CHECK: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QAE@XZ"
145 // X64: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QEAA@XZ"
146 UnsignedLongLongTemplate<(unsigned long long)-1> uint64_neg_1;
147 // CHECK: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QAE@XZ"
148 // X64: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QEAA@XZ"
149 }
150
151 namespace space {
foo(const T & l)152 template<class T> const T& foo(const T& l) { return l; }
153 }
154 // CHECK: "\01??$foo@H@space@@YAABHABH@Z"
155 // X64: "\01??$foo@H@space@@YAAEBHAEBH@Z"
156
use()157 void use() {
158 space::foo(42);
159 }
160
161 // PR13455
162 typedef void (*FunctionPointer)(void);
163
164 template <FunctionPointer function>
FunctionPointerTemplate()165 void FunctionPointerTemplate() {
166 function();
167 }
168
spam()169 void spam() {
170 FunctionPointerTemplate<spam>();
171 // CHECK: "\01??$FunctionPointerTemplate@$1?spam@@YAXXZ@@YAXXZ"
172 // X64: "\01??$FunctionPointerTemplate@$1?spam@@YAXXZ@@YAXXZ"
173 }
174
175 // Unlike Itanium, there is no character code to indicate an argument pack.
176 // Tested with MSVC 2013, the first version which supports variadic templates.
177
variadic_fn_template(const Ts &...args)178 template <typename ...Ts> void variadic_fn_template(const Ts &...args) { }
variadic_fn_instantiate()179 void variadic_fn_instantiate() {
180 variadic_fn_template(0, 1, 3, 4);
181 variadic_fn_template(0, 1, 'a', "b");
182 }
183 // CHECK: "\01??$variadic_fn_template@HHHH@@YAXABH000@Z"
184 // CHECK: "\01??$variadic_fn_template@HHD$$BY01D@@YAXABH0ABDAAY01$$CBD@Z"
185
186 template <typename ...Ts>
187 struct VariadicClass {
VariadicClassVariadicClass188 VariadicClass() { }
189 int x;
190 };
variadic_class_instantiate()191 void variadic_class_instantiate() {
192 VariadicClass<int, char, bool> a;
193 VariadicClass<bool, char, int> b;
194 }
195 // CHECK: call {{.*}} @"\01??0?$VariadicClass@HD_N@@QAE@XZ"
196 // CHECK: call {{.*}} @"\01??0?$VariadicClass@_NDH@@QAE@XZ"
197
198 template <typename T>
199 struct Second {};
200
201 template <typename T, template <class> class>
202 struct Type {};
203
204 template <template <class> class T>
205 struct Type2 {};
206
207 template <template <class> class T, bool B>
208 struct Thing;
209
210 template <template <class> class T>
211 struct Thing<T, false> { };
212
213 template <template <class> class T>
214 struct Thing<T, true> { };
215
template_template_fun(Type<Thing<Second,true>,Second>)216 void template_template_fun(Type<Thing<Second, true>, Second>) { }
217 // CHECK: "\01?template_template_fun@@YAXU?$Type@U?$Thing@USecond@@$00@@USecond@@@@@Z"
218
219 template <typename T>
220 void template_template_specialization();
221
222 template <>
template_template_specialization()223 void template_template_specialization<void (Type<Thing<Second, true>, Second>)>() {
224 }
225 // CHECK: "\01??$template_template_specialization@$$A6AXU?$Type@U?$Thing@USecond@@$00@@USecond@@@@@Z@@YAXXZ"
226
227 // PR16788
228 template <decltype(nullptr)> struct S1 {};
f(S1<nullptr>)229 void f(S1<nullptr>) {}
230 // CHECK: "\01?f@@YAXU?$S1@$0A@@@@Z"
231
232 struct record {
233 int first;
234 int second;
235 };
236 template <const record &>
237 struct type1 {
238 };
239 extern const record inst;
recref(type1<inst>)240 void recref(type1<inst>) {}
241 // CHECK: "\01?recref@@YAXU?$type1@$E?inst@@3Urecord@@B@@@Z"
242
243 struct _GUID {};
244 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
245
246 template <typename T, const _GUID *G = &__uuidof(T)>
247 struct UUIDType1 {};
248
249 template <typename T, const _GUID &G = __uuidof(T)>
250 struct UUIDType2 {};
251
fun(UUIDType1<uuid> a)252 void fun(UUIDType1<uuid> a) {}
253 // CHECK: "\01?fun@@YAXU?$UUIDType1@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
fun(UUIDType2<uuid> b)254 void fun(UUIDType2<uuid> b) {}
255 // CHECK: "\01?fun@@YAXU?$UUIDType2@Uuuid@@$E?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
256
257 template <typename T> struct TypeWithFriendDefinition {
FunctionDefinedWithInjectedName(TypeWithFriendDefinition<T>)258 friend void FunctionDefinedWithInjectedName(TypeWithFriendDefinition<T>) {}
259 };
260 // CHECK: call {{.*}} @"\01?FunctionDefinedWithInjectedName@@YAXU?$TypeWithFriendDefinition@H@@@Z"
CallFunctionDefinedWithInjectedName()261 void CallFunctionDefinedWithInjectedName() {
262 FunctionDefinedWithInjectedName(TypeWithFriendDefinition<int>());
263 }
264 // CHECK: @"\01?FunctionDefinedWithInjectedName@@YAXU?$TypeWithFriendDefinition@H@@@Z"
265
266 // We need to be able to feed GUIDs through a couple rounds of template
267 // substitution.
268 template <const _GUID *G>
269 struct UUIDType3 {
fooUUIDType3270 void foo() {}
271 };
272 template <const _GUID *G>
273 struct UUIDType4 : UUIDType3<G> {
barUUIDType4274 void bar() { UUIDType4::foo(); }
275 };
276 template struct UUIDType4<&__uuidof(uuid)>;
277 // CHECK: "\01?bar@?$UUIDType4@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@QAEXXZ"
278 // CHECK: "\01?foo@?$UUIDType3@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@QAEXXZ"
279