blob: 46ab251af14f8373c74a41419c0c80f58d305452 [file] [log] [blame]
Hans Wennborgc9bd88e2014-01-14 19:35:09 +00001// 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
Charles Davis5511dfb2012-05-26 23:12:19 +00003
4template<typename T>
5class Class {
6 public:
Peter Collingbourne2816c022013-04-25 04:25:40 +00007 Class() {}
Charles Davis5511dfb2012-05-26 23:12:19 +00008};
9
10class Typename { };
11
12template<typename T>
13class Nested { };
14
15template<bool flag>
16class BoolTemplate {
17 public:
18 BoolTemplate() {}
19};
20
Charles Davis7fb195b2012-05-28 00:43:56 +000021template<int param>
22class IntTemplate {
23 public:
24 IntTemplate() {}
25};
26
Will Wilsone74c2812014-12-11 05:47:10 +000027template<unsigned param>
28class UnsignedIntTemplate {
29public:
30 UnsignedIntTemplate() {}
31};
32
David Majnemer2a816452013-12-09 10:44:32 +000033template<long long param>
34class LongLongTemplate {
35 public:
36 LongLongTemplate() {}
37};
38
39template<unsigned long long param>
40class UnsignedLongLongTemplate {
41 public:
42 UnsignedLongLongTemplate() {}
43};
44
Charles Davisde2e5ed2012-06-23 00:27:49 +000045template<>
46class BoolTemplate<true> {
47 public:
48 BoolTemplate() {}
49 template<class T> void Foo(T arg) {}
50};
51
Charles Davis5511dfb2012-05-26 23:12:19 +000052void template_mangling() {
53 Class<Typename> c1;
Peter Collingbourne2816c022013-04-25 04:25:40 +000054// CHECK: call {{.*}} @"\01??0?$Class@VTypename@@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000055// X64: call {{.*}} @"\01??0?$Class@VTypename@@@@QEAA@XZ"
Charles Davis5511dfb2012-05-26 23:12:19 +000056
Reid Kleckner5fdaac12013-04-09 12:47:38 +000057 Class<const Typename> c1_const;
Peter Collingbourne2816c022013-04-25 04:25:40 +000058// CHECK: call {{.*}} @"\01??0?$Class@$$CBVTypename@@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000059// X64: call {{.*}} @"\01??0?$Class@$$CBVTypename@@@@QEAA@XZ"
Reid Kleckner5fdaac12013-04-09 12:47:38 +000060 Class<volatile Typename> c1_volatile;
Peter Collingbourne2816c022013-04-25 04:25:40 +000061// CHECK: call {{.*}} @"\01??0?$Class@$$CCVTypename@@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000062// X64: call {{.*}} @"\01??0?$Class@$$CCVTypename@@@@QEAA@XZ"
Reid Kleckner5fdaac12013-04-09 12:47:38 +000063 Class<const volatile Typename> c1_cv;
Peter Collingbourne2816c022013-04-25 04:25:40 +000064// CHECK: call {{.*}} @"\01??0?$Class@$$CDVTypename@@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000065// X64: call {{.*}} @"\01??0?$Class@$$CDVTypename@@@@QEAA@XZ"
Reid Kleckner5fdaac12013-04-09 12:47:38 +000066
Charles Davis5511dfb2012-05-26 23:12:19 +000067 Class<Nested<Typename> > c2;
Peter Collingbourne2816c022013-04-25 04:25:40 +000068// CHECK: call {{.*}} @"\01??0?$Class@V?$Nested@VTypename@@@@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000069// X64: call {{.*}} @"\01??0?$Class@V?$Nested@VTypename@@@@@@QEAA@XZ"
Peter Collingbourne2816c022013-04-25 04:25:40 +000070
71 Class<int * const> c_intpc;
72// CHECK: call {{.*}} @"\01??0?$Class@QAH@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000073// X64: call {{.*}} @"\01??0?$Class@QEAH@@QEAA@XZ"
Peter Collingbourne2816c022013-04-25 04:25:40 +000074 Class<int()> c_ft;
75// CHECK: call {{.*}} @"\01??0?$Class@$$A6AHXZ@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000076// X64: call {{.*}} @"\01??0?$Class@$$A6AHXZ@@QEAA@XZ"
Peter Collingbourne2816c022013-04-25 04:25:40 +000077 Class<int[]> c_inti;
78// CHECK: call {{.*}} @"\01??0?$Class@$$BY0A@H@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000079// X64: call {{.*}} @"\01??0?$Class@$$BY0A@H@@QEAA@XZ"
Peter Collingbourne2816c022013-04-25 04:25:40 +000080 Class<int[5]> c_int5;
81// CHECK: call {{.*}} @"\01??0?$Class@$$BY04H@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000082// X64: call {{.*}} @"\01??0?$Class@$$BY04H@@QEAA@XZ"
Peter Collingbourne2816c022013-04-25 04:25:40 +000083 Class<const int[5]> c_intc5;
84// CHECK: call {{.*}} @"\01??0?$Class@$$BY04$$CBH@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000085// X64: call {{.*}} @"\01??0?$Class@$$BY04$$CBH@@QEAA@XZ"
Peter Collingbourne2816c022013-04-25 04:25:40 +000086 Class<int * const[5]> c_intpc5;
87// CHECK: call {{.*}} @"\01??0?$Class@$$BY04QAH@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000088// X64: call {{.*}} @"\01??0?$Class@$$BY04QEAH@@QEAA@XZ"
Charles Davis5511dfb2012-05-26 23:12:19 +000089
90 BoolTemplate<false> _false;
91// CHECK: call {{.*}} @"\01??0?$BoolTemplate@$0A@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000092// X64: call {{.*}} @"\01??0?$BoolTemplate@$0A@@@QEAA@XZ"
Charles Davis5511dfb2012-05-26 23:12:19 +000093
94 BoolTemplate<true> _true;
Charles Davisde2e5ed2012-06-23 00:27:49 +000095 // PR13158
96 _true.Foo(1);
Charles Davis5511dfb2012-05-26 23:12:19 +000097// CHECK: call {{.*}} @"\01??0?$BoolTemplate@$00@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +000098// X64: call {{.*}} @"\01??0?$BoolTemplate@$00@@QEAA@XZ"
Charles Davisde2e5ed2012-06-23 00:27:49 +000099// CHECK: call {{.*}} @"\01??$Foo@H@?$BoolTemplate@$00@@QAEXH@Z"
Reid Kleckner369f3162013-05-14 20:30:42 +0000100// X64: call {{.*}} @"\01??$Foo@H@?$BoolTemplate@$00@@QEAAXH@Z"
Charles Davis7fb195b2012-05-28 00:43:56 +0000101
Nico Weber7d37f052012-11-08 23:38:59 +0000102 IntTemplate<0> zero;
103// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0A@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +0000104// X64: call {{.*}} @"\01??0?$IntTemplate@$0A@@@QEAA@XZ"
Nico Weber7d37f052012-11-08 23:38:59 +0000105
Charles Davis6770dea2012-05-28 16:53:33 +0000106 IntTemplate<5> five;
107// CHECK: call {{.*}} @"\01??0?$IntTemplate@$04@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +0000108// X64: call {{.*}} @"\01??0?$IntTemplate@$04@@QEAA@XZ"
Charles Davis6770dea2012-05-28 16:53:33 +0000109
Charles Davis7fb195b2012-05-28 00:43:56 +0000110 IntTemplate<11> eleven;
111// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0L@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +0000112// X64: call {{.*}} @"\01??0?$IntTemplate@$0L@@@QEAA@XZ"
Charles Davis7fb195b2012-05-28 00:43:56 +0000113
Nico Weber90a415e2012-10-03 13:39:49 +0000114 IntTemplate<256> _256;
115// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0BAA@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +0000116// X64: call {{.*}} @"\01??0?$IntTemplate@$0BAA@@@QEAA@XZ"
Nico Weber90a415e2012-10-03 13:39:49 +0000117
118 IntTemplate<513> _513;
119// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0CAB@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +0000120// X64: call {{.*}} @"\01??0?$IntTemplate@$0CAB@@@QEAA@XZ"
Nico Weber90a415e2012-10-03 13:39:49 +0000121
122 IntTemplate<1026> _1026;
123// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0EAC@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +0000124// X64: call {{.*}} @"\01??0?$IntTemplate@$0EAC@@@QEAA@XZ"
Nico Weber90a415e2012-10-03 13:39:49 +0000125
Charles Davis7fb195b2012-05-28 00:43:56 +0000126 IntTemplate<65535> ffff;
127// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0PPPP@@@QAE@XZ"
Reid Kleckner369f3162013-05-14 20:30:42 +0000128// X64: call {{.*}} @"\01??0?$IntTemplate@$0PPPP@@@QEAA@XZ"
David Majnemer2a816452013-12-09 10:44:32 +0000129
130 IntTemplate<-1> neg_1;
131// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?0@@QAE@XZ"
132// X64: call {{.*}} @"\01??0?$IntTemplate@$0?0@@QEAA@XZ"
133 IntTemplate<-9> neg_9;
134// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?8@@QAE@XZ"
135// X64: call {{.*}} @"\01??0?$IntTemplate@$0?8@@QEAA@XZ"
136 IntTemplate<-10> neg_10;
137// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?9@@QAE@XZ"
138// X64: call {{.*}} @"\01??0?$IntTemplate@$0?9@@QEAA@XZ"
139 IntTemplate<-11> neg_11;
140// CHECK: call {{.*}} @"\01??0?$IntTemplate@$0?L@@@QAE@XZ"
141// X64: call {{.*}} @"\01??0?$IntTemplate@$0?L@@@QEAA@XZ"
Will Wilsone74c2812014-12-11 05:47:10 +0000142
143 UnsignedIntTemplate<4294967295> ffffffff;
144// CHECK: call {{.*}} @"\01??0?$UnsignedIntTemplate@$0PPPPPPPP@@@QAE@XZ"
145// X64: call {{.*}} @"\01??0?$UnsignedIntTemplate@$0PPPPPPPP@@@QEAA@XZ"
David Majnemer2a816452013-12-09 10:44:32 +0000146
147 LongLongTemplate<-9223372036854775807LL-1LL> int64_min;
148// CHECK: call {{.*}} @"\01??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QAE@XZ"
149// X64: call {{.*}} @"\01??0?$LongLongTemplate@$0?IAAAAAAAAAAAAAAA@@@QEAA@XZ"
150 LongLongTemplate<9223372036854775807LL> int64_max;
151// CHECK: call {{.*}} @"\01??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QAE@XZ"
152// X64: call {{.*}} @"\01??0?$LongLongTemplate@$0HPPPPPPPPPPPPPPP@@@QEAA@XZ"
153 UnsignedLongLongTemplate<18446744073709551615ULL> uint64_max;
154// CHECK: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QAE@XZ"
155// X64: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QEAA@XZ"
156 UnsignedLongLongTemplate<(unsigned long long)-1> uint64_neg_1;
157// CHECK: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QAE@XZ"
158// X64: call {{.*}} @"\01??0?$UnsignedLongLongTemplate@$0?0@@QEAA@XZ"
Charles Davis5511dfb2012-05-26 23:12:19 +0000159}
160
161namespace space {
162 template<class T> const T& foo(const T& l) { return l; }
163}
164// CHECK: "\01??$foo@H@space@@YAABHABH@Z"
Reid Kleckner369f3162013-05-14 20:30:42 +0000165// X64: "\01??$foo@H@space@@YAAEBHAEBH@Z"
Charles Davis5511dfb2012-05-26 23:12:19 +0000166
167void use() {
168 space::foo(42);
169}
Reid Kleckner831b71e2013-03-20 22:29:42 +0000170
171// PR13455
172typedef void (*FunctionPointer)(void);
173
174template <FunctionPointer function>
175void FunctionPointerTemplate() {
176 function();
177}
178
179void spam() {
180 FunctionPointerTemplate<spam>();
181// CHECK: "\01??$FunctionPointerTemplate@$1?spam@@YAXXZ@@YAXXZ"
Reid Kleckner369f3162013-05-14 20:30:42 +0000182// X64: "\01??$FunctionPointerTemplate@$1?spam@@YAXXZ@@YAXXZ"
Reid Kleckner831b71e2013-03-20 22:29:42 +0000183}
Reid Klecknerf0ae35b2013-07-02 18:10:07 +0000184
185// Unlike Itanium, there is no character code to indicate an argument pack.
186// Tested with MSVC 2013, the first version which supports variadic templates.
187
188template <typename ...Ts> void variadic_fn_template(const Ts &...args) { }
189void variadic_fn_instantiate() {
190 variadic_fn_template(0, 1, 3, 4);
191 variadic_fn_template(0, 1, 'a', "b");
192}
193// CHECK: "\01??$variadic_fn_template@HHHH@@YAXABH000@Z"
194// CHECK: "\01??$variadic_fn_template@HHD$$BY01D@@YAXABH0ABDAAY01$$CBD@Z"
195
196template <typename ...Ts>
197struct VariadicClass {
198 VariadicClass() { }
199 int x;
200};
201void variadic_class_instantiate() {
202 VariadicClass<int, char, bool> a;
203 VariadicClass<bool, char, int> b;
204}
205// CHECK: call {{.*}} @"\01??0?$VariadicClass@HD_N@@QAE@XZ"
206// CHECK: call {{.*}} @"\01??0?$VariadicClass@_NDH@@QAE@XZ"
David Majnemerae465ef2013-08-05 21:33:59 +0000207
David Majnemer0db0ca42013-08-05 22:26:46 +0000208template <typename T>
209struct Second {};
210
211template <typename T, template <class> class>
212struct Type {};
213
214template <template <class> class T>
215struct Type2 {};
216
217template <template <class> class T, bool B>
218struct Thing;
219
220template <template <class> class T>
221struct Thing<T, false> { };
222
223template <template <class> class T>
224struct Thing<T, true> { };
225
226void template_template_fun(Type<Thing<Second, true>, Second>) { }
227// CHECK: "\01?template_template_fun@@YAXU?$Type@U?$Thing@USecond@@$00@@USecond@@@@@Z"
228
229template <typename T>
230void template_template_specialization();
231
232template <>
233void template_template_specialization<void (Type<Thing<Second, true>, Second>)>() {
234}
235// CHECK: "\01??$template_template_specialization@$$A6AXU?$Type@U?$Thing@USecond@@$00@@USecond@@@@@Z@@YAXXZ"
236
David Majnemerae465ef2013-08-05 21:33:59 +0000237// PR16788
238template <decltype(nullptr)> struct S1 {};
239void f(S1<nullptr>) {}
240// CHECK: "\01?f@@YAXU?$S1@$0A@@@@Z"
David Majnemere8fdc062013-08-13 01:25:35 +0000241
242struct record {
243 int first;
244 int second;
245};
246template <const record &>
247struct type1 {
248};
249extern const record inst;
250void recref(type1<inst>) {}
251// CHECK: "\01?recref@@YAXU?$type1@$E?inst@@3Urecord@@B@@@Z"
David Majnemer8eaab6f2013-08-13 06:32:20 +0000252
253struct _GUID {};
254struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
255
256template <typename T, const _GUID *G = &__uuidof(T)>
257struct UUIDType1 {};
258
259template <typename T, const _GUID &G = __uuidof(T)>
260struct UUIDType2 {};
261
262void fun(UUIDType1<uuid> a) {}
263// CHECK: "\01?fun@@YAXU?$UUIDType1@Uuuid@@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
264void fun(UUIDType2<uuid> b) {}
265// CHECK: "\01?fun@@YAXU?$UUIDType2@Uuuid@@$E?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@@Z"
David Majnemerf0a84f22013-08-16 08:29:13 +0000266
267template <typename T> struct TypeWithFriendDefinition {
268 friend void FunctionDefinedWithInjectedName(TypeWithFriendDefinition<T>) {}
269};
270// CHECK: call {{.*}} @"\01?FunctionDefinedWithInjectedName@@YAXU?$TypeWithFriendDefinition@H@@@Z"
271void CallFunctionDefinedWithInjectedName() {
272 FunctionDefinedWithInjectedName(TypeWithFriendDefinition<int>());
273}
274// CHECK: @"\01?FunctionDefinedWithInjectedName@@YAXU?$TypeWithFriendDefinition@H@@@Z"
Reid Klecknerb4848e72014-06-10 20:06:25 +0000275
276// We need to be able to feed GUIDs through a couple rounds of template
277// substitution.
278template <const _GUID *G>
279struct UUIDType3 {
280 void foo() {}
281};
282template <const _GUID *G>
283struct UUIDType4 : UUIDType3<G> {
284 void bar() { UUIDType4::foo(); }
285};
286template struct UUIDType4<&__uuidof(uuid)>;
287// CHECK: "\01?bar@?$UUIDType4@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@QAEXXZ"
288// CHECK: "\01?foo@?$UUIDType3@$1?_GUID_12345678_1234_1234_1234_1234567890ab@@3U__s_GUID@@B@@QAEXXZ"