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