1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks -std=c++11 | FileCheck %s 2 struct X { }; 3 struct Y { }; 4 5 // CHECK: @unmangled_variable = global 6 // CHECK: @_ZN1N1iE = global 7 // CHECK: @_ZZN1N1fEiiE1b = internal global 8 // CHECK: @_ZZN1N1gEvE1a = internal global 9 // CHECK: @_ZGVZN1N1gEvE1a = internal global 10 11 //CHECK: @pr5966_i = external global 12 //CHECK: @_ZL8pr5966_i = internal global 13 14 // CHECK: define zeroext i1 @_ZplRK1YRA100_P1X 15 bool operator+(const Y&, X* (&xs)[100]) { return false; } 16 17 // CHECK: define void @_Z1f1s 18 typedef struct { int a; } s; 19 void f(s) { } 20 21 // CHECK: define void @_Z1f1e 22 typedef enum { foo } e; 23 void f(e) { } 24 25 // CHECK: define void @_Z1f1u 26 typedef union { int a; } u; 27 void f(u) { } 28 29 // CHECK: define void @_Z1f1x 30 typedef struct { int a; } x,y; 31 void f(y) { } 32 33 // CHECK: define void @_Z1fv 34 void f() { } 35 36 // CHECK: define void @_ZN1N1fEv 37 namespace N { void f() { } } 38 39 // CHECK: define void @_ZN1N1N1fEv 40 namespace N { namespace N { void f() { } } } 41 42 // CHECK: define void @unmangled_function 43 extern "C" { namespace N { void unmangled_function() { } } } 44 45 extern "C" { namespace N { int unmangled_variable = 10; } } 46 47 namespace N { int i; } 48 49 namespace N { int f(int, int) { static int b; return b; } } 50 51 namespace N { int h(); void g() { static int a = h(); } } 52 53 // CHECK: define void @_Z1fno 54 void f(__int128_t, __uint128_t) { } 55 56 template <typename T> struct S1 {}; 57 58 // CHECK: define void @_Z1f2S1IiE 59 void f(S1<int>) {} 60 61 // CHECK: define void @_Z1f2S1IdE 62 void f(S1<double>) {} 63 64 template <int N> struct S2 {}; 65 // CHECK: define void @_Z1f2S2ILi100EE 66 void f(S2<100>) {} 67 68 // CHECK: define void @_Z1f2S2ILin100EE 69 void f(S2<-100>) {} 70 71 template <bool B> struct S3 {}; 72 73 // CHECK: define void @_Z1f2S3ILb1EE 74 void f(S3<true>) {} 75 76 // CHECK: define void @_Z1f2S3ILb0EE 77 void f(S3<false>) {} 78 79 struct S; 80 81 // CHECK: define void @_Z1fM1SKFvvE 82 void f(void (S::*)() const) {} 83 84 // CHECK: define void @_Z1fM1SFvvE 85 void f(void (S::*)()) {} 86 87 // CHECK: define void @_Z1fi 88 void f(const int) { } 89 90 template<typename T, typename U> void ft1(U u, T t) { } 91 92 template<typename T> void ft2(T t, void (*)(T), void (*)(T)) { } 93 94 template<typename T, typename U = S1<T> > struct S4 { }; 95 template<typename T> void ft3(S4<T>*) { } 96 97 namespace NS { 98 template<typename T> void ft1(T) { } 99 } 100 101 void g1() { 102 // CHECK: @_Z3ft1IidEvT0_T_ 103 ft1<int, double>(1, 0); 104 105 // CHECK: @_Z3ft2IcEvT_PFvS0_ES2_ 106 ft2<char>(1, 0, 0); 107 108 // CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE 109 ft3<int>(0); 110 111 // CHECK: @_ZN2NS3ft1IiEEvT_ 112 NS::ft1<int>(1); 113 } 114 115 // Expressions 116 template<int I> struct S5 { }; 117 118 template<int I> void ft4(S5<I>) { } 119 void g2() { 120 // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE 121 ft4(S5<10>()); 122 123 // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE 124 ft4(S5<20>()); 125 } 126 127 extern "C++" { 128 // CHECK: @_Z1hv 129 void h() { } 130 } 131 132 // PR5019 133 extern "C" { struct a { int b; }; } 134 135 // CHECK: @_Z1fP1a 136 int f(struct a *x) { 137 return x->b; 138 } 139 140 // PR5017 141 extern "C" { 142 struct Debug { 143 const Debug& operator<< (unsigned a) const { return *this; } 144 }; 145 Debug dbg; 146 // CHECK: @_ZNK5DebuglsEj 147 int main(void) { dbg << 32 ;} 148 } 149 150 template<typename T> struct S6 { 151 typedef int B; 152 }; 153 154 template<typename T> void ft5(typename S6<T>::B) { } 155 // CHECK: @_Z3ft5IiEvN2S6IT_E1BE 156 template void ft5<int>(int); 157 158 template<typename T> class A {}; 159 160 namespace NS { 161 template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; } 162 } 163 164 // CHECK: @_ZN2NSeqIcEEbRK1AIT_ES5_ 165 template bool NS::operator==(const ::A<char>&, const ::A<char>&); 166 167 namespace std { 168 template<typename T> bool operator==(const A<T>&, const A<T>&) { return true; } 169 } 170 171 // CHECK: @_ZSteqIcEbRK1AIT_ES4_ 172 template bool std::operator==(const ::A<char>&, const ::A<char>&); 173 174 struct S { 175 typedef int U; 176 }; 177 178 template <typename T> typename T::U ft6(const T&) { return 0; } 179 180 // CHECK: @_Z3ft6I1SENT_1UERKS1_ 181 template int ft6<S>(const S&); 182 183 template<typename> struct __is_scalar_type { 184 enum { __value = 1 }; 185 }; 186 187 template<bool, typename> struct __enable_if { }; 188 189 template<typename T> struct __enable_if<true, T> { 190 typedef T __type; 191 }; 192 193 // PR5063 194 template<typename T> typename __enable_if<__is_scalar_type<T>::__value, void>::__type ft7() { } 195 196 // CHECK: @_Z3ft7IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 197 template void ft7<int>(); 198 // CHECK: @_Z3ft7IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 199 template void ft7<void*>(); 200 201 // PR5144 202 extern "C" { 203 void extern_f(void); 204 }; 205 206 // CHECK: @extern_f 207 void extern_f(void) { } 208 209 struct S7 { 210 S7(); 211 212 struct S { S(); }; 213 struct { 214 S s; 215 } a; 216 }; 217 218 // PR5139 219 // CHECK: @_ZN2S7C1Ev 220 // CHECK: @_ZN2S7C2Ev 221 // CHECK: @"_ZN2S73$_0C1Ev" 222 S7::S7() {} 223 224 // PR5063 225 template<typename T> typename __enable_if<(__is_scalar_type<T>::__value), void>::__type ft8() { } 226 // CHECK: @_Z3ft8IiEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 227 template void ft8<int>(); 228 // CHECK: @_Z3ft8IPvEN11__enable_ifIXsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 229 template void ft8<void*>(); 230 231 // PR5796 232 namespace PR5796 { 233 template<typename> struct __is_scalar_type { 234 enum { __value = 0 }; 235 }; 236 237 template<bool, typename> struct __enable_if {}; 238 template<typename T> struct __enable_if<true, T> { typedef T __type; }; 239 template<typename T> 240 241 // CHECK: define linkonce_odr void @_ZN6PR57968__fill_aIiEENS_11__enable_ifIXntsr16__is_scalar_typeIT_EE7__valueEvE6__typeEv 242 typename __enable_if<!__is_scalar_type<T>::__value, void>::__type __fill_a() { }; 243 244 void f() { __fill_a<int>(); } 245 } 246 247 namespace Expressions { 248 // Unary operators. 249 250 // CHECK: define weak_odr void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i 251 template <int i> void f1(int (*)[(-i) + 2]) { }; 252 template void f1<1>(int (*)[1]); 253 254 // CHECK: define weak_odr void @_ZN11Expressions2f2ILi1EEEvPApsT__i 255 template <int i> void f2(int (*)[+i]) { }; 256 template void f2<1>(int (*)[1]); 257 258 // Binary operators. 259 260 // CHECK: define weak_odr void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i 261 template <int i> void f3(int (*)[i+i]) { }; 262 template void f3<1>(int (*)[2]); 263 264 // CHECK: define weak_odr void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i 265 template <int i> void f4(int (*)[2 + i+i]) { }; 266 template void f4<1>(int (*)[4]); 267 268 // The ternary operator. 269 // CHECK: define weak_odr void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i 270 template <bool b> void f4(int (*)[b ? 1 : 2]) { }; 271 template void f4<true>(int (*)[1]); 272 } 273 274 struct Ops { 275 Ops& operator+(const Ops&); 276 Ops& operator-(const Ops&); 277 Ops& operator&(const Ops&); 278 Ops& operator*(const Ops&); 279 280 void *v; 281 }; 282 283 // CHECK: define %struct.Ops* @_ZN3OpsplERKS_ 284 Ops& Ops::operator+(const Ops&) { return *this; } 285 // CHECK: define %struct.Ops* @_ZN3OpsmiERKS_ 286 Ops& Ops::operator-(const Ops&) { return *this; } 287 // CHECK: define %struct.Ops* @_ZN3OpsanERKS_ 288 Ops& Ops::operator&(const Ops&) { return *this; } 289 // CHECK: define %struct.Ops* @_ZN3OpsmlERKS_ 290 Ops& Ops::operator*(const Ops&) { return *this; } 291 292 // PR5861 293 namespace PR5861 { 294 template<bool> class P; 295 template<> class P<true> {}; 296 297 template<template <bool> class, bool> 298 struct Policy { }; 299 300 template<typename T, typename = Policy<P, true> > class Alloc 301 { 302 T *allocate(int, const void*) { return 0; } 303 }; 304 305 // CHECK: define weak_odr i8* @_ZN6PR58615AllocIcNS_6PolicyINS_1PELb1EEEE8allocateEiPKv 306 template class Alloc<char>; 307 } 308 309 // CHECK: define void @_Z1fU13block_pointerFiiiE 310 void f(int (^)(int, int)) { } 311 312 void pr5966_foo() { 313 extern int pr5966_i; 314 pr5966_i = 0; 315 } 316 317 static int pr5966_i; 318 319 void pr5966_bar() { 320 pr5966_i = 0; 321 } 322 323 namespace test0 { 324 int ovl(int x); 325 char ovl(double x); 326 327 template <class T> void f(T, char (&buffer)[sizeof(ovl(T()))]) {} 328 329 void test0() { 330 char buffer[1]; 331 f(0.0, buffer); 332 } 333 // CHECK: define void @_ZN5test05test0Ev() 334 // CHECK: define linkonce_odr void @_ZN5test01fIdEEvT_RAszcl3ovlcvS1__EE_c( 335 336 void test1() { 337 char buffer[sizeof(int)]; 338 f(1, buffer); 339 } 340 // CHECK: define void @_ZN5test05test1Ev() 341 // CHECK: define linkonce_odr void @_ZN5test01fIiEEvT_RAszcl3ovlcvS1__EE_c( 342 343 template <class T> void g(char (&buffer)[sizeof(T() + 5.0f)]) {} 344 void test2() { 345 char buffer[sizeof(float)]; 346 g<float>(buffer); 347 } 348 // CHECK: define linkonce_odr void @_ZN5test01gIfEEvRAszplcvT__ELf40a00000E_c( 349 350 template <class T> void h(char (&buffer)[sizeof(T() + 5.0)]) {} 351 void test3() { 352 char buffer[sizeof(double)]; 353 h<float>(buffer); 354 } 355 // CHECK: define linkonce_odr void @_ZN5test01hIfEEvRAszplcvT__ELd4014000000000000E_c( 356 357 template <class T> void j(char (&buffer)[sizeof(T().buffer)]) {} 358 struct A { double buffer[128]; }; 359 void test4() { 360 char buffer[1024]; 361 j<A>(buffer); 362 } 363 // CHECK: define linkonce_odr void @_ZN5test01jINS_1AEEEvRAszdtcvT__E6buffer_c( 364 } 365 366 namespace test1 { 367 template<typename T> struct X { }; 368 template<template<class> class Y, typename T> void f(Y<T>) { } 369 // CHECK: define weak_odr void @_ZN5test11fINS_1XEiEEvT_IT0_E 370 template void f(X<int>); 371 } 372 373 // CHECK: define internal void @_ZL27functionWithInternalLinkagev() 374 static void functionWithInternalLinkage() { } 375 void g() { functionWithInternalLinkage(); } 376 377 namespace test2 { 378 template <class T> decltype(((T*) 0)->member) read_member(T& obj) { 379 return obj.member; 380 } 381 382 struct A { int member; } obj; 383 int test() { 384 return read_member(obj); 385 } 386 387 // CHECK: define linkonce_odr i32 @_ZN5test211read_memberINS_1AEEEDtptcvPT_Li0E6memberERS2_( 388 } 389 390 // rdar://problem/9280586 391 namespace test3 { 392 struct AmbiguousBase { int ab; }; 393 struct Path1 : AmbiguousBase { float p; }; 394 struct Path2 : AmbiguousBase { double p; }; 395 struct Derived : Path1, Path2 { }; 396 397 // CHECK: define linkonce_odr i32 @_ZN5test38get_ab_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E2abERS2_( 398 template <class T> decltype(((T*) 0)->Path1::ab) get_ab_1(T &ref) { return ref.Path1::ab; } 399 400 // CHECK: define linkonce_odr i32 @_ZN5test38get_ab_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E2abERS2_( 401 template <class T> decltype(((T*) 0)->Path2::ab) get_ab_2(T &ref) { return ref.Path2::ab; } 402 403 // CHECK: define linkonce_odr float @_ZN5test37get_p_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E1pERS2_( 404 template <class T> decltype(((T*) 0)->Path1::p) get_p_1(T &ref) { return ref.Path1::p; } 405 406 // CHECK: define linkonce_odr double @_ZN5test37get_p_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E1pERS2_( 407 template <class T> decltype(((T*) 0)->Path2::p) get_p_2(T &ref) { return ref.Path2::p; } 408 409 Derived obj; 410 void test() { 411 get_ab_1(obj); 412 get_ab_2(obj); 413 get_p_1(obj); 414 get_p_2(obj); 415 } 416 } 417 418 // CHECK: define void @_ZN5test41gEPNS_3zedIXadL_ZNS_3foo3barEEEEE 419 namespace test4 { 420 struct foo { int bar; }; 421 template <int (foo::*)> 422 struct zed {}; 423 void g(zed<&foo::bar>*) 424 {} 425 } 426 // CHECK: define void @_ZN5test51gEPNS_3zedIXadL_ZNS_3foo3barEEEEE 427 namespace test5 { 428 struct foo { static int bar; }; 429 template <int *> 430 struct zed {}; 431 void g(zed<&foo::bar>*) 432 {} 433 } 434 // CHECK: define void @_ZN5test61gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE 435 namespace test6 { 436 struct foo { int bar(); }; 437 template <int (foo::*)()> 438 struct zed {}; 439 void g(zed<&foo::bar>*) 440 {} 441 } 442 // CHECK: define void @_ZN5test71gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE 443 namespace test7 { 444 struct foo { static int bar(); }; 445 template <int (*f)()> 446 struct zed {}; 447 void g(zed<&foo::bar>*) 448 {} 449 } 450 // CHECK: define weak_odr void @_ZN5test81AILZNS_1B5valueEEE3incEv 451 namespace test8 { 452 template <int &counter> class A { void inc() { counter++; } }; 453 class B { public: static int value; }; 454 template class A<B::value>; 455 } 456 // CHECK: declare void @_ZN5test91fIiNS_3barEEEvRKNT0_3baz1XE 457 namespace test9 { 458 template<class T> 459 struct foo { 460 typedef T X; 461 }; 462 struct bar { 463 typedef foo<int> baz; 464 }; 465 template <class zaz, class zed> 466 void f(const typename zed::baz::X&); 467 void g() { 468 f<int, bar>( 0); 469 } 470 } 471 472 // <rdar://problem/7825453> 473 namespace test10 { 474 template <char P1> struct S {}; 475 template <char P2> void f(struct S<false ? 'a' : P2> ) {} 476 477 // CHECK: define weak_odr void @_ZN6test101fILc3EEEvNS_1SIXquLb0ELc97ET_EEE( 478 template void f<(char) 3>(struct S<3>); 479 } 480 481 namespace test11 { 482 // CHECK: @_ZN6test111fEz 483 void f(...) { } 484 485 struct A { 486 void f(...); 487 }; 488 489 // CHECK: @_ZN6test111A1fEz 490 void A::f(...) { } 491 } 492 493 namespace test12 { 494 495 // CHECK: _ZN6test121fENS_1AILt33000EEE 496 template <unsigned short> struct A { }; 497 void f(A<33000>) { } 498 } 499 500 // PR7446 501 namespace test13 { 502 template <template <class> class T> class A {}; 503 template <class U> class B {}; 504 505 template <template<class> class T> void foo(const A<T> &a) {} 506 507 // CHECK: define weak_odr void @_ZN6test133fooINS_1BEEEvRKNS_1AIT_EE( 508 template void foo(const A<B> &a); 509 } 510 511 namespace test14 { 512 extern "C" { 513 struct S { 514 static int a(), x; 515 }; 516 // CHECK: define i32 @_ZN6test141S1aEv 517 // CHECK: load i32* @_ZN6test141S1xE 518 int S::a() { return S::x; } 519 } 520 } 521 522 // rdar://problem/8204122 523 namespace test15 { 524 enum E { e = 3 }; 525 template <int I> struct S {}; 526 527 template <int I> void f(S<I + e>) {} 528 529 // CHECK: define weak_odr void @_ZN6test151fILi7EEEvNS_1SIXplT_LNS_1EE3EEEE( 530 template void f<7>(S<7 + e>); 531 } 532 533 // rdar://problem/8302148 534 namespace test17 { 535 template <int N> struct A {}; 536 537 struct B { 538 static int foo(void); 539 }; 540 541 template <class T> A<sizeof(T::foo())> func(void); 542 543 // CHECK: define void @_ZN6test174testEv() 544 // CHECK: call {{.*}} @_ZN6test174funcINS_1BEEENS_1AIXszclsrT_3fooEEEEv() 545 void test() { 546 func<B>(); 547 } 548 } 549 550 // PR7891 551 namespace test18 { 552 struct A { 553 int operator+(); 554 int operator-(); 555 int operator*(); 556 int operator&(); 557 }; 558 template <int (A::*)()> struct S {}; 559 560 template <typename T> void f(S<&T::operator+>) {} 561 template void f<A>(S<&A::operator+>); 562 563 template <typename T> void f(S<&T::operator- >) {} 564 template void f<A>(S<&A::operator- >); 565 566 template <typename T> void f(S<&T::operator*>) {} 567 template void f<A>(S<&A::operator*>); 568 569 template <typename T> void f(S<&T::operator&>) {} 570 template void f<A>(S<&A::operator&>); 571 572 // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_plEEE 573 // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_miEEE 574 // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_mlEEE 575 // CHECK: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_anEEE 576 } 577 578 // rdar://problem/8332117 579 namespace test19 { 580 struct A { 581 template <typename T> int f(); 582 int operator+(); 583 operator int(); 584 template <typename T> int operator-(); 585 }; 586 587 template <int (A::*)()> struct S {}; 588 589 template <typename T> void g (S<&T::template f<int> >) {} 590 template <typename T> void g (S<&T::operator+ >) {} 591 template <typename T> void g (S<&T::operator int>) {} 592 template <typename T> void g (S<&T::template operator- <double> >) {} 593 594 // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_1fIiEEEE( 595 template void g<A>(S<&A::f<int> >); 596 // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_plEEE( 597 template void g<A>(S<&A::operator+>); 598 // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_cviEEE( 599 template void g<A>(S<&A::operator int>); 600 // CHECK: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_miIdEEEE( 601 template void g<A>(S<&A::operator-<double> >); 602 } 603 604 namespace test20 { 605 template <class T> T *f(const T&); 606 template <class T> T *f(T*); 607 608 // CHECK: define weak_odr void @_ZN6test205test0IiEEvDTcl1fIPT_ELi0EEE( 609 template <class T> void test0(decltype(f<T*>(0))) {} 610 template void test0<int>(decltype(f<int*>(0))); 611 612 // CHECK: define weak_odr void @_ZN6test205test1IiEEvDTcl1fIEcvT__EEE( 613 template <class T> void test1(decltype(f<>(T()))) {} 614 template void test1<int>(decltype(f<>(int()))); 615 } 616 617 // rdar:// 8620510 618 namespace test21 { 619 // CHECK: define void @_ZN6test2112vla_arg_funcEiPA_i( 620 void vla_arg_func(int X, int a[X][X]) {} 621 } 622 623 namespace test22 { 624 // CHECK: define void @_ZN6test221fEDn( 625 void f(decltype(nullptr)) { } 626 } 627 628 // rdar://problem/8913416 629 namespace test23 { 630 typedef void * const vpc; 631 632 // CHECK: define void @_ZN6test231fERA10_KPv( 633 void f(vpc (&)[10]) {} 634 635 typedef vpc vpca5[5]; 636 void f(vpca5 volatile (&)[10]) {} 637 // CHECK: define void @_ZN6test231fERA10_A5_VKPv( 638 } 639 640 namespace test24 { 641 void test0() { 642 extern int foo(); 643 // CHECK: call i32 @_ZN6test243fooEv() 644 foo(); 645 } 646 647 static char foo() {} 648 void test1() { 649 // CHECK: call signext i8 @_ZN6test24L3fooEv() 650 foo(); 651 } 652 } 653 654 // rdar://problem/8806641 655 namespace test25 { 656 template <void (*fn)()> struct A { 657 static void call() { fn(); } 658 }; 659 void foo(); 660 void test() { 661 // CHECK: call void @_ZN6test251AIXadL_ZNS_3fooEvEEE4callEv() 662 A<foo>::call(); 663 } 664 } 665 666 namespace test26 { 667 template <template <class> class T> void foo(decltype(T<float>::object) &object) {} 668 669 template <class T> struct holder { static T object; }; 670 671 void test() { 672 float f; 673 674 // CHECK: call void @_ZN6test263fooINS_6holderEEEvRDtsrT_IfE6objectE( 675 foo<holder>(f); 676 } 677 } 678 679 namespace test27 { 680 struct A { 681 struct inner { 682 float object; 683 }; 684 685 float meth(); 686 }; 687 typedef A Alias; 688 689 template <class T> void a(decltype(T::inner::object) &object) {} 690 template <class T> void b(decltype(T().Alias::meth()) &object) {} 691 692 void test() { 693 float f; 694 // CHECK: call void @_ZN6test271aINS_1AEEEvRDtsrNT_5innerE6objectE( 695 a<A>(f); 696 // CHECK: call void @_ZN6test271bINS_1AEEEvRDTcldtcvT__Esr5AliasE4methEE( 697 b<A>(f); 698 } 699 } 700 701 // An injected class name type in a unresolved-name. 702 namespace test28 { 703 template <class T> struct A { 704 enum { bit }; 705 }; 706 707 template <class T> void foo(decltype(A<T>::A::bit) x); 708 709 void test() { 710 foo<char>(A<char>::bit); 711 // CHECK: call void @_ZN6test283fooIcEEvDtsr1AIT_E1AE3bitE( 712 } 713 } 714 715 // An enclosing template type parameter in an unresolved-name. 716 namespace test29 { 717 template <class T> struct A { 718 template <class U> static void foo(decltype(T::fn(U())) x); 719 }; 720 struct B { static int fn(int); static long fn(long); }; 721 722 void test() { 723 A<B>::foo<int>(0); 724 // CHECK: call void @_ZN6test291AINS_1BEE3fooIiEEvDTclsrS1_2fncvT__EEE( 725 } 726 } 727 728 // An enclosing template template parameter in an unresolved-name. 729 namespace test30 { 730 template <template <class> class T> struct A { 731 template <class U> static void foo(decltype(T<U>::fn()) x); 732 }; 733 template <class T> struct B { static T fn(); }; 734 735 void test() { 736 A<B>::foo<int>(0); 737 // CHECK: call void @_ZN6test301AINS_1BEE3fooIiEEvDTclsrS1_IT_EE2fnEE( 738 } 739 } 740 741 namespace test31 { // instantiation-dependent mangling of decltype 742 int x; 743 template<class T> auto f1(T p)->decltype(x) { return 0; } 744 // The return type in the mangling of the template signature 745 // is encoded as "i". 746 template<class T> auto f2(T p)->decltype(p) { return 0; } 747 // The return type in the mangling of the template signature 748 // is encoded as "Dtfp_E". 749 void g(int); 750 template<class T> auto f3(T p)->decltype(g(p)) {} 751 752 // CHECK: define weak_odr i32 @_ZN6test312f1IiEEiT_( 753 template int f1(int); 754 // CHECK: define weak_odr i32 @_ZN6test312f2IiEEDtfp_ET_ 755 template int f2(int); 756 // CHECK: define weak_odr void @_ZN6test312f3IiEEDTcl1gfp_EET_ 757 template void f3(int); 758 } 759 760 // PR10205 761 namespace test32 { 762 template<typename T, int=T::value> struct A { 763 typedef int type; 764 }; 765 struct B { enum { value = 4 }; }; 766 767 template <class T> typename A<T>::type foo() { return 0; } 768 void test() { 769 foo<B>(); 770 // CHECK: call i32 @_ZN6test323fooINS_1BEEENS_1AIT_XsrS3_5valueEE4typeEv() 771 } 772 } 773 774 namespace test33 { 775 template <class T> struct X { 776 enum { value = T::value }; 777 }; 778 779 template<typename T, int=X<T>::value> struct A { 780 typedef int type; 781 }; 782 struct B { enum { value = 4 }; }; 783 784 template <class T> typename A<T>::type foo() { return 0; } 785 786 void test() { 787 foo<B>(); 788 // CHECK: call i32 @_ZN6test333fooINS_1BEEENS_1AIT_Xsr1XIS3_EE5valueEE4typeEv() 789 } 790 } 791 792 namespace test34 { 793 // Mangling for instantiation-dependent decltype expressions. 794 template<typename T> 795 void f(decltype(sizeof(decltype(T() + T())))) {} 796 797 // CHECK: define weak_odr void @_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE 798 template void f<int>(decltype(sizeof(1))); 799 800 // Mangling for non-instantiation-dependent sizeof expressions. 801 template<unsigned N> 802 void f2(int (&)[N + sizeof(int*)]) {} 803 804 // CHECK: define weak_odr void @_ZN6test342f2ILj4EEEvRAplT_Lm8E_i 805 template void f2<4>(int (&)[4 + sizeof(int*)]); 806 807 // Mangling for non-instantiation-dependent sizeof expressions 808 // involving an implicit conversion of the result of the sizeof. 809 template<unsigned long long N> 810 void f3(int (&)[N + sizeof(int*)]) {} 811 812 // CHECK: define weak_odr void @_ZN6test342f3ILy4EEEvRAplT_Ly8E_i 813 template void f3<4>(int (&)[4 + sizeof(int*)]); 814 815 // Mangling for instantiation-dependent sizeof() expressions as 816 // template arguments. 817 template<unsigned> struct A { }; 818 819 template<typename T> void f4(::test34::A<sizeof(sizeof(decltype(T() + T())))>) { } 820 821 // CHECK: define weak_odr void @_ZN6test342f4IiEEvNS_1AIXszstDTplcvT__EcvS2__EEEEE 822 template void f4<int>(A<sizeof(sizeof(int))>); 823 } 824 825 namespace test35 { 826 // Dependent operator names of unknown arity. 827 struct A { 828 template<typename U> A operator+(U) const; 829 }; 830 831 template<typename T> 832 void f1(decltype(sizeof(&T::template operator+<int>))) {} 833 834 // CHECK: define weak_odr void @_ZN6test352f1INS_1AEEEvDTszadsrT_plIiEE 835 template void f1<A>(__SIZE_TYPE__); 836 } 837 838 namespace test36 { 839 template<unsigned> struct A { }; 840 841 template<typename ...Types> 842 auto f1(Types... values) -> A<sizeof...(values)> { } 843 844 // CHECK: define weak_odr {{.*}} @_ZN6test362f1IJifEEENS_1AIXsZfp_EEEDpT_ 845 template A<2> f1(int, float); 846 } 847