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