1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -fblocks -std=c++11 | FileCheck %s
5 // CHECK: @unmangled_variable ={{.*}} global
6 // CHECK: @_ZN1N1iE ={{.*}} global
7 // CHECK: @_ZZN1N1fEiiE1b = internal global
8 // CHECK: @_ZZN1N1gEvE1a = internal global
9 // CHECK: @_ZGVZN1N1gEvE1a = internal global
11 //CHECK: @pr5966_i = external global
12 //CHECK: @_ZL8pr5966_j = internal global
14 // CHECK-LABEL: define{{.*}} zeroext i1 @_ZplRK1YRA100_P1X
15 bool operator+(const Y
&, X
* (&xs
)[100]) { return false; }
17 // CHECK-LABEL: define{{.*}} void @_Z1f1s
18 typedef struct { int a
; } s
;
21 // CHECK-LABEL: define{{.*}} void @_Z1f1e
22 typedef enum { foo
} e
;
25 // CHECK-LABEL: define{{.*}} void @_Z1f1u
26 typedef union { int a
; } u
;
29 // CHECK-LABEL: define{{.*}} void @_Z1f1x
30 typedef struct { int a
; } x
,y
;
33 // CHECK-LABEL: define{{.*}} void @_Z1fv
36 // CHECK-LABEL: define{{.*}} void @_ZN1N1fEv
37 namespace N
{ void f() { } }
39 // CHECK-LABEL: define{{.*}} void @_ZN1N1N1fEv
40 namespace N
{ namespace N
{ void f() { } } }
42 // CHECK-LABEL: define{{.*}} void @unmangled_function
43 extern "C" { namespace N
{ void unmangled_function() { } } }
45 extern "C" { namespace N
{ int unmangled_variable
= 10; } }
47 namespace N
{ int i
; }
49 namespace N
{ int f(int, int) { static int b
; return b
; } }
51 namespace N
{ int h(); void g() { static int a
= h(); } }
53 // CHECK-LABEL: define{{.*}} void @_Z1fno
54 void f(__int128_t
, __uint128_t
) {}
56 template <typename T
> struct S1
{};
58 // CHECK-LABEL: define{{.*}} void @_Z1f2S1IiE
61 // CHECK-LABEL: define{{.*}} void @_Z1f2S1IdE
64 template <int N
> struct S2
{};
65 // CHECK-LABEL: define{{.*}} void @_Z1f2S2ILi100EE
68 // CHECK-LABEL: define{{.*}} void @_Z1f2S2ILin100EE
71 template <bool B
> struct S3
{};
73 // CHECK-LABEL: define{{.*}} void @_Z1f2S3ILb1EE
76 // CHECK-LABEL: define{{.*}} void @_Z1f2S3ILb0EE
81 // CHECK-LABEL: define{{.*}} void @_Z1fM1SKFvvE
82 void f(void (S::*)() const) {}
84 // CHECK-LABEL: define{{.*}} void @_Z1fM1SFvvE
85 void f(void (S::*)()) {}
87 // CHECK-LABEL: define{{.*}} void @_Z1fi
90 template<typename T
, typename U
> void ft1(U u
, T t
) { }
92 template<typename T
> void ft2(T t
, void (*)(T
), void (*)(T
)) { }
94 template<typename T
, typename U
= S1
<T
> > struct S4
{ };
95 template<typename T
> void ft3(S4
<T
>*) { }
98 template<typename T
> void ft1(T
) { }
102 // CHECK: @_Z3ft1IidEvT0_T_
103 ft1
<int, double>(1, 0);
105 // CHECK: @_Z3ft2IcEvT_PFvS0_ES2_
108 // CHECK: @_Z3ft3IiEvP2S4IT_2S1IS1_EE
111 // CHECK: @_ZN2NS3ft1IiEEvT_
116 template<int I
> struct S5
{ };
118 template<int I
> void ft4(S5
<I
>) { }
120 // CHECK: @_Z3ft4ILi10EEv2S5IXT_EE
123 // CHECK: @_Z3ft4ILi20EEv2S5IXT_EE
133 extern "C" { struct a
{ int b
; }; }
143 const Debug
& operator<< (unsigned a
) const { return *this; }
146 // CHECK: @_ZNK5DebuglsEj
147 int main(void) { dbg
<< 32 ;}
150 template<typename T
> struct S6
{
154 template<typename T
> void ft5(typename S6
<T
>::B
) { }
155 // CHECK: @_Z3ft5IiEvN2S6IT_E1BE
156 template void ft5
<int>(int);
158 template<typename T
> class A
{};
161 template<typename T
> bool operator==(const A
<T
>&, const A
<T
>&) { return true; }
164 // CHECK: @_ZN2NSeqIcEEbRK1AIT_ES5_
165 template bool NS::operator==(const ::A
<char>&, const ::A
<char>&);
168 template<typename T
> bool operator==(const A
<T
>&, const A
<T
>&) { return true; }
171 // CHECK: @_ZSteqIcEbRK1AIT_ES4_
172 template bool std::operator==(const ::A
<char>&, const ::A
<char>&);
178 template <typename T
> typename
T::U
ft6(const T
&) { return 0; }
180 // CHECK: @_Z3ft6I1SENT_1UERKS1_
181 template int ft6
<S
>(const S
&);
183 template<typename
> struct __is_scalar_type
{
184 enum { __value
= 1 };
187 template<bool, typename
> struct __enable_if
{ };
189 template<typename T
> struct __enable_if
<true, T
> {
194 template<typename T
> typename __enable_if
<__is_scalar_type
<T
>::__value
, void>::__type
ft7() { }
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*>();
207 void extern_f(void) { }
219 // CHECK: @_ZN2S7C2Ev
220 // CHECK: @_ZN2S7Ut_C1Ev
221 // CHECK: @_ZN2S7C1Ev
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*>();
233 template<typename
> struct __is_scalar_type
{
234 enum { __value
= 0 };
237 template<bool, typename
> struct __enable_if
{};
238 template<typename T
> struct __enable_if
<true, T
> { typedef T __type
; };
241 // CHECK-LABEL: 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() { };
244 void f() { __fill_a
<int>(); }
247 namespace Expressions
{
250 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i
251 template <int i
> void f1(int (*)[(-i
) + 2]) { };
252 template void f1
<1>(int (*)[1]);
254 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f2ILi1EEEvPApsT__i
255 template <int i
> void f2(int (*)[+i
]) { };
256 template void f2
<1>(int (*)[1]);
260 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i
261 template <int i
> void f3(int (*)[i
+i
]) { };
262 template void f3
<1>(int (*)[2]);
264 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i
265 template <int i
> void f4(int (*)[2 + i
+i
]) { };
266 template void f4
<1>(int (*)[4]);
268 // The ternary operator.
269 // CHECK-LABEL: define weak_odr void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i
270 template <bool b
> void f4(int (*)[b
? 1 : 2]) { };
271 template void f4
<true>(int (*)[1]);
275 Ops
& operator+(const Ops
&);
276 Ops
& operator-(const Ops
&);
277 Ops
& operator&(const Ops
&);
278 Ops
& operator*(const Ops
&);
283 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3OpsplERKS_
284 Ops
& Ops::operator+(const Ops
&) { return *this; }
285 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3OpsmiERKS_
286 Ops
& Ops::operator-(const Ops
&) { return *this; }
287 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3OpsanERKS_
288 Ops
& Ops::operator&(const Ops
&) { return *this; }
289 // CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3OpsmlERKS_
290 Ops
& Ops::operator*(const Ops
&) { return *this; }
294 template<bool> class P
;
295 template<> class P
<true> {};
297 template<template <bool> class, bool>
300 template<typename T
, typename
= Policy
<P
, true> > class Alloc
302 T
*allocate(int, const void*) { return 0; }
305 // CHECK-LABEL: define weak_odr noundef ptr @_ZN6PR58615AllocIcNS_6PolicyINS_1PELb1EEEE8allocateEiPKv
306 template class Alloc
<char>;
309 // CHECK-LABEL: define{{.*}} void @_Z1fU13block_pointerFiiiE
310 void f(int (^)(int, int)) { }
327 template <class T
> void f(T
, char (&buffer
)[sizeof(ovl(T()))]) {}
333 // CHECK-LABEL: define{{.*}} void @_ZN5test05test0Ev()
334 // CHECK-LABEL: define linkonce_odr void @_ZN5test01fIdEEvT_RAszcl3ovlcvS1__EE_c(
337 char buffer
[sizeof(int)];
340 // CHECK-LABEL: define{{.*}} void @_ZN5test05test1Ev()
341 // CHECK-LABEL: define linkonce_odr void @_ZN5test01fIiEEvT_RAszcl3ovlcvS1__EE_c(
343 template <class T
> void g(char (&buffer
)[sizeof(T() + 5.0f
)]) {}
345 char buffer
[sizeof(float)];
348 // CHECK-LABEL: define linkonce_odr void @_ZN5test01gIfEEvRAszplcvT__ELf40a00000E_c(
350 template <class T
> void h(char (&buffer
)[sizeof(T() + 5.0)]) {}
352 char buffer
[sizeof(double)];
355 // CHECK-LABEL: define linkonce_odr void @_ZN5test01hIfEEvRAszplcvT__ELd4014000000000000E_c(
357 template <class T
> void j(char (&buffer
)[sizeof(T().buffer
)]) {}
358 struct A
{ double buffer
[128]; };
363 // CHECK-LABEL: define linkonce_odr void @_ZN5test01jINS_1AEEEvRAszdtcvT__E6buffer_c(
365 template <class T
> void k(char (&buffer
)[sizeof(T() + 0.0f
)]) {}
367 char buffer
[sizeof(float)];
370 // CHECK-LABEL: define linkonce_odr void @_ZN5test01kIfEEvRAszplcvT__ELf00000000E_c(
375 template<typename T
> struct X
{ };
376 template<template<class> class Y
, typename T
> void f(Y
<T
>) { }
377 // CHECK-LABEL: define weak_odr void @_ZN5test11fINS_1XEiEEvT_IT0_E
378 template void f(X
<int>);
381 // CHECK-LABEL: define internal void @_ZL27functionWithInternalLinkagev()
382 static void functionWithInternalLinkage() { }
383 void g() { functionWithInternalLinkage(); }
386 template <class T
> decltype(((T
*) 0)->member
) read_member(T
& obj
) {
390 struct A
{ int member
; } obj
;
392 return read_member(obj
);
395 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN5test211read_memberINS_1AEEEDtptcvPT_Li0E6memberERS2_(
398 // rdar://problem/9280586
400 struct AmbiguousBase
{ int ab
; };
401 struct Path1
: AmbiguousBase
{ float p
; };
402 struct Path2
: AmbiguousBase
{ double p
; };
403 struct Derived
: Path1
, Path2
{ };
405 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN5test38get_ab_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E2abERS2_(
406 template <class T
> decltype(((T
*) 0)->Path1::ab
) get_ab_1(T
&ref
) { return ref
.Path1::ab
; }
408 // CHECK-LABEL: define linkonce_odr noundef i32 @_ZN5test38get_ab_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E2abERS2_(
409 template <class T
> decltype(((T
*) 0)->Path2::ab
) get_ab_2(T
&ref
) { return ref
.Path2::ab
; }
411 // CHECK-LABEL: define linkonce_odr noundef float @_ZN5test37get_p_1INS_7DerivedEEEDtptcvPT_Li0Esr5Path1E1pERS2_(
412 template <class T
> decltype(((T
*) 0)->Path1::p
) get_p_1(T
&ref
) { return ref
.Path1::p
; }
414 // CHECK-LABEL: define linkonce_odr noundef double @_ZN5test37get_p_2INS_7DerivedEEEDtptcvPT_Li0Esr5Path2E1pERS2_(
415 template <class T
> decltype(((T
*) 0)->Path2::p
) get_p_2(T
&ref
) { return ref
.Path2::p
; }
426 // CHECK-LABEL: define{{.*}} void @_ZN5test41gEPNS_3zedIXadL_ZNS_3foo3barEEEEE
428 struct foo
{ int bar
; };
429 template <int (foo::*)>
431 void g(zed
<&foo::bar
>*)
434 // CHECK-LABEL: define{{.*}} void @_ZN5test51gEPNS_3zedIXadL_ZNS_3foo3barEEEEE
436 struct foo
{ static int bar
; };
439 void g(zed
<&foo::bar
>*)
442 // CHECK-LABEL: define{{.*}} void @_ZN5test61gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE
444 struct foo
{ int bar(); };
445 template <int (foo::*)()>
447 void g(zed
<&foo::bar
>*)
450 // CHECK-LABEL: define{{.*}} void @_ZN5test71gEPNS_3zedIXadL_ZNS_3foo3barEvEEEE
452 struct foo
{ static int bar(); };
453 template <int (*f
)()>
455 void g(zed
<&foo::bar
>*)
458 // CHECK-LABEL: define weak_odr void @_ZN5test81AIL_ZNS_1B5valueEEE3incEv
460 template <int &counter
> class A
{ void inc() { counter
++; } };
461 class B
{ public: static int value
; };
462 template class A
<B::value
>;
464 // CHECK: declare void @_ZN5test91fIiNS_3barEEEvRKNT0_3baz1XE
471 typedef foo
<int> baz
;
473 template <class zaz
, class zed
>
474 void f(const typename
zed::baz::X
&);
480 // <rdar://problem/7825453>
482 template <char P1
> struct S
{};
483 template <char P2
> void f(struct S
<false ? 'a' : P2
> ) {}
485 // CHECK-LABEL: define weak_odr void @_ZN6test101fILc3EEEvNS_1SIXquLb0ELc97ET_EEE(
486 template void f
<(char) 3>(struct S
<3>);
490 // CHECK: @_ZN6test111fEz
497 // CHECK: @_ZN6test111A1fEz
503 // CHECK: _ZN6test121fENS_1AILt33000EEE
504 template <unsigned short> struct A
{ };
510 template <template <class> class T
> class A
{};
511 template <class U
> class B
{};
513 template <template<class> class T
> void foo(const A
<T
> &a
) {}
515 // CHECK-LABEL: define weak_odr void @_ZN6test133fooINS_1BEEEvRKNS_1AIT_EE(
516 template void foo(const A
<B
> &a
);
524 // CHECK-LABEL: define{{.*}} i32 @_ZN6test141S1aEv
525 // CHECK: load i32, ptr @_ZN6test141S1xE
526 int S::a() { return S::x
; }
530 // rdar://problem/8204122
533 template <int I
> struct S
{};
535 template <int I
> void f(S
<I
+ e
>) {}
537 // CHECK-LABEL: define weak_odr void @_ZN6test151fILi7EEEvNS_1SIXplT_LNS_1EE3EEEE(
538 template void f
<7>(S
<7 + e
>);
541 // rdar://problem/8302148
543 template <int N
> struct A
{};
546 static int foo(void);
549 template <class T
> A
<sizeof(T::foo())> func(void);
551 // CHECK-LABEL: define{{.*}} void @_ZN6test174testEv()
552 // CHECK: call {{.*}} @_ZN6test174funcINS_1BEEENS_1AIXszclsrT_3fooEEEEv()
566 template <int (A::*)()> struct S
{};
568 template <typename T
> void f(S
<&T::operator+>) {}
569 template void f
<A
>(S
<&A::operator+>);
571 template <typename T
> void f(S
<&T::operator- >) {}
572 template void f
<A
>(S
<&A::operator- >);
574 template <typename T
> void f(S
<&T::operator*>) {}
575 template void f
<A
>(S
<&A::operator*>);
577 template <typename T
> void f(S
<&T::operator&>) {}
578 template void f
<A
>(S
<&A::operator&>);
580 // CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onplEEE
581 // CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onmiEEE
582 // CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onmlEEE
583 // CHECK-LABEL: define weak_odr void @_ZN6test181fINS_1AEEEvNS_1SIXadsrT_onanEEE
586 // rdar://problem/8332117
589 template <typename T
> int f();
592 template <typename T
> int operator-();
595 template <int (A::*)()> struct S
{};
597 template <typename T
> void g (S
<&T::template f
<int> >) {}
598 template <typename T
> void g (S
<&T::operator+ >) {}
599 template <typename T
> void g (S
<&T::operator int>) {}
600 template <typename T
> void g (S
<&T::template operator- <double> >) {}
602 // CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_1fIiEEEE(
603 template void g
<A
>(S
<&A::f
<int> >);
604 // CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_onplEEE(
605 template void g
<A
>(S
<&A::operator+>);
606 // CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_oncviEEE(
607 template void g
<A
>(S
<&A::operator int>);
608 // CHECK-LABEL: define weak_odr void @_ZN6test191gINS_1AEEEvNS_1SIXadsrT_onmiIdEEEE(
609 template void g
<A
>(S
<&A::operator-<double> >);
613 template <class T
> T
*f(const T
&);
614 template <class T
> T
*f(T
*);
616 // CHECK-LABEL: define weak_odr void @_ZN6test205test0IiEEvDTcl1fIPT_ELi0EEE(
617 template <class T
> void test0(decltype(f
<T
*>(0))) {}
618 template void test0
<int>(decltype(f
<int*>(0)));
620 // CHECK-LABEL: define weak_odr void @_ZN6test205test1IiEEvDTcl1fIEcvT__EEE(
621 template <class T
> void test1(decltype(f
<>(T()))) {}
622 template void test1
<int>(decltype(f
<>(int())));
627 // CHECK-LABEL: define{{.*}} void @_ZN6test2112vla_arg_funcEiPA_i(
628 void vla_arg_func(int X
, int a
[X
][X
]) {}
632 // CHECK-LABEL: define{{.*}} void @_ZN6test221fEDn(
633 void f(decltype(nullptr)) { }
636 // rdar://problem/8913416
638 typedef void * const vpc
;
640 // CHECK-LABEL: define{{.*}} void @_ZN6test231fERA10_KPv(
641 void f(vpc (&)[10]) {}
643 typedef vpc vpca5
[5];
644 void f(vpca5
volatile (&)[10]) {}
645 // CHECK-LABEL: define{{.*}} void @_ZN6test231fERA10_A5_VKPv(
651 // CHECK: call noundef i32 @_ZN6test243fooEv()
657 // CHECK: call noundef signext i8 @_ZN6test24L3barEv()
662 // rdar://problem/8806641
664 template <void (*fn
)()> struct A
{
665 static void call() { fn(); }
669 // CHECK: call void @_ZN6test251AIXadL_ZNS_3fooEvEEE4callEv()
675 template <template <class> class T
> void foo(decltype(T
<float>::object
) &object
) {}
677 template <class T
> struct holder
{ static T object
; };
682 // CHECK: call void @_ZN6test263fooINS_6holderEEEvRDtsrT_IfE6objectE(
697 template <class T
> void a(decltype(T::inner::object
) &object
) {}
698 template <class T
> void b(decltype(T().Alias::meth()) &object
) {}
702 // CHECK: call void @_ZN6test271aINS_1AEEEvRDtsrNT_5innerE6objectE(
704 // CHECK: call void @_ZN6test271bINS_1AEEEvRDTcldtcvT__Esr5AliasE4methEE(
709 // An injected class name type in a unresolved-name.
711 template <class T
> struct A
{
715 template <class T
> void foo(decltype(A
<T
>::A::bit
) x
);
718 foo
<char>(A
<char>::bit
);
719 // CHECK: call void @_ZN6test283fooIcEEvDtsr1AIT_E1AE3bitE(
723 // An enclosing template type parameter in an unresolved-name.
725 template <class T
> struct A
{
726 template <class U
> static void foo(decltype(T::fn(U())) x
);
728 struct B
{ static int fn(int); static long fn(long); };
732 // CHECK: call void @_ZN6test291AINS_1BEE3fooIiEEvDTclsrS1_2fncvT__EEE(
736 // An enclosing template template parameter in an unresolved-name.
738 template <template <class> class T
> struct A
{
739 template <class U
> static void foo(decltype(T
<U
>::fn()) x
);
741 template <class T
> struct B
{ static T
fn(); };
745 // CHECK: call void @_ZN6test301AINS_1BEE3fooIiEEvDTclsrS1_IT_EE2fnEE(
749 namespace test31
{ // instantiation-dependent mangling of decltype
751 template<class T
> auto f1(T p
)->decltype(x
) { return 0; }
752 // The return type in the mangling of the template signature
753 // is encoded as "i".
754 template<class T
> auto f2(T p
)->decltype(p
) { return 0; }
755 // The return type in the mangling of the template signature
756 // is encoded as "Dtfp_E".
758 template<class T
> auto f3(T p
)->decltype(g(p
)) {}
760 // CHECK-LABEL: define weak_odr noundef i32 @_ZN6test312f1IiEEiT_(
761 template int f1(int);
762 // CHECK-LABEL: define weak_odr noundef i32 @_ZN6test312f2IiEEDtfp_ET_
763 template int f2(int);
764 // CHECK-LABEL: define weak_odr void @_ZN6test312f3IiEEDTcl1gfp_EET_
765 template void f3(int);
770 template<typename T
, int=T::value
> struct A
{
773 struct B
{ enum { value
= 4 }; };
775 template <class T
> typename A
<T
>::type
foo() { return 0; }
778 // CHECK: call noundef i32 @_ZN6test323fooINS_1BEEENS_1AIT_XsrS3_5valueEE4typeEv()
783 template <class T
> struct X
{
784 enum { value
= T::value
};
787 template<typename T
, int=X
<T
>::value
> struct A
{
790 struct B
{ enum { value
= 4 }; };
792 template <class T
> typename A
<T
>::type
foo() { return 0; }
796 // CHECK: call noundef i32 @_ZN6test333fooINS_1BEEENS_1AIT_Xsr1XIS3_EE5valueEE4typeEv()
801 // Mangling for instantiation-dependent decltype expressions.
803 void f(decltype(sizeof(decltype(T() + T())))) {}
805 // CHECK-LABEL: define weak_odr void @_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE
806 template void f
<int>(decltype(sizeof(1)));
808 // Mangling for non-instantiation-dependent sizeof expressions.
810 void f2(int (&)[N
+ sizeof(int*)]) {}
812 // CHECK-LABEL: define weak_odr void @_ZN6test342f2ILj4EEEvRAplT_Lm8E_i
813 template void f2
<4>(int (&)[4 + sizeof(int*)]);
815 // Mangling for non-instantiation-dependent sizeof expressions
816 // involving an implicit conversion of the result of the sizeof.
817 template<unsigned long long N
>
818 void f3(int (&)[N
+ sizeof(int*)]) {}
820 // CHECK-LABEL: define weak_odr void @_ZN6test342f3ILy4EEEvRAplT_Ly8E_i
821 template void f3
<4>(int (&)[4 + sizeof(int*)]);
823 // Mangling for instantiation-dependent sizeof() expressions as
824 // template arguments.
825 template<unsigned> struct A
{ };
827 template<typename T
> void f4(::test34::A
<sizeof(sizeof(decltype(T() + T())))>) { }
829 // CHECK-LABEL: define weak_odr void @_ZN6test342f4IiEEvNS_1AIXszstDTplcvT__EcvS2__EEEEE
830 template void f4
<int>(A
<sizeof(sizeof(int))>);
834 // Dependent operator names of unknown arity.
836 template <typename U
> A
operator+(U
) const;
840 void f1(decltype(sizeof(&T::template operator+<int>))) {}
842 // CHECK-LABEL: define weak_odr void @_ZN6test352f1INS_1AEEEvDTszadsrT_onplIiEE
843 template void f1
<A
>(__SIZE_TYPE__
);
847 template<unsigned> struct A
{ };
849 template<typename
...Types
>
850 auto f1(Types
... values
) -> A
<sizeof...(values
)> { }
852 // CHECK: define weak_odr {{.*}} @_ZN6test362f1IJifEEENS_1AIXsZfp_EEEDpT_
853 template A
<2> f1(int, float);
860 typedef struct { } b
;
861 typedef struct { } *c
;
865 template<typename T
> void func(T
) { }
867 // CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt_EEEvT_
869 // CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt0_EEEvT_
871 // CHECK-LABEL: define linkonce_odr void @_ZN6test374funcINS_3fooUt1_EEEvT_
876 // CHECK-LABEL: define{{.*}} void @_Z6ASfuncPU3AS3i
877 void ASfunc(__attribute__((address_space(3))) int* x
) {}
880 // CHECK-LABEL: define linkonce_odr void @_ZN6test384funcINS_3fooUt_EEEvT_
886 template <typename T
> void func(T
) {}
887 void test() { func(foo().a
); }
891 // CHECK-LABEL: define internal void @"_ZN6test394funcINS_3$_03$_1EEEvT_"
895 template<typename T
> void func(T
) {}
903 // CHECK: ptr {{.*}} @_ZZN6test401fEvE1a_0
916 // CHECK: define linkonce_odr void @_ZN6test414funcINS_1XEEEvNS_3fooILi20ES1_EE
917 template <int i
, class T
> struct foo
{
918 template <class T2
= T
> friend void func(foo x
) {}
923 void g() { func(foo
<20, X
>()); }
927 // CHECK: define linkonce_odr void @_ZN6test424funcINS_1XEEEvNS_3fooILi20ES1_EE
928 template <int i
, template <class> class T
> struct foo
{
929 template <template <class> class T2
= T
> friend void func(foo x
) {}
932 template <class V
> struct X
{
935 void g() { func(foo
<20, X
>()); }
939 // CHECK-LABEL: define{{.*}} void @_ZN6test431gEPNS_3zedIXadL_ZNS_3fooUt_3barEEEEE
940 struct foo
{ union { int bar
; }; };
941 template <int (foo::*)>
943 void g(zed
<&foo::bar
>*)
948 struct foo
{ void bar() __restrict
{ }; } obj
;
953 // CHECK-LABEL: define linkonce_odr void @_ZN6test443foo3barEv(ptr {{[^,]*}} %this)
960 template <typename T
>
961 void f(enum T::e
*) {}
962 template void f
<S
>(S::e
*);
963 // CHECK-LABEL: define weak_odr void @_ZN6test451fINS_1SEEEvPTeNT_1eE(ptr noundef %0)
970 template <typename T
>
971 void f(struct T::s
*) {}
972 template void f
<S
>(S::s
*);
973 // CHECK-LABEL: define weak_odr void @_ZN6test461fINS_1SEEEvPTsNT_1sE(ptr noundef %0)
980 template <typename T
>
981 void f(class T::c
*) {}
982 template void f
<S
>(S::c
*);
983 // CHECK-LABEL: define weak_odr void @_ZN6test471fINS_1SEEEvPTsNT_1cE(ptr noundef %0)
990 template <typename T
>
991 void f(union T::u
*) {}
992 template void f
<S
>(S::u
*);
993 // CHECK-LABEL: define weak_odr void @_ZN6test481fINS_1SEEEvPTuNT_1uE(ptr noundef %0)
1000 template <template <int> class T
>
1004 // CHECK-LABEL: declare void @_ZN6test493finINS_1SEEET_ILi3EES3_()
1011 template <template <int> class T
>
1015 // CHECK-LABEL: declare void @_ZN6test503finINS_1SEEET_ILi3EES2_ILi4EE()
1019 template <typename T
>
1020 decltype(T().~T()) fun() {}
1021 template void fun
<int>();
1022 // CHECK-LABEL: @_ZN6test513funIiEEDTcldtcvT__EdnS1_EEv
1023 template void fun
<X
>();
1024 // CHECK-LABEL: @_ZN6test513funI1XEEDTcldtcvT__EdnS2_EEv
1025 template void fun
<S1
<int> >();
1026 // CHECK-LABEL: @_ZN6test513funI2S1IiEEEDTcldtcvT__EdnS3_EEv
1029 template <typename T
>
1034 template <typename T
>
1035 decltype(S1
<T
>().~S1
<T
>()) fun1() {};
1036 template <typename U
, typename T
>
1037 decltype(U().~S1
<T
>()) fun2() {}
1038 template <typename U
, typename T
>
1039 decltype(S1
<T
>().~U()) fun3() {}
1040 template <typename T
>
1041 decltype(S1
<T
>().~S1
<T
>(), S1
<T
>().~S1
<T
>()) fun4() {};
1042 template <typename T
>
1043 decltype(S1
<int>().~S1
<T
>()) fun5(){};
1044 template <template <typename T
> class U
>
1045 decltype(S1
<int>().~U
<int>()) fun6(){};
1046 template <typename T
>
1047 decltype(E().E::~T()) fun7() {}
1048 template <template <typename
> class U
>
1049 decltype(X
<int>::Y().U
<int>::Y::~Y()) fun8() {}
1050 template void fun1
<int>();
1051 // CHECK-LABEL: @_ZN6test514fun1IiEEDTcldtcv2S1IT_E_Edn2S1IS2_EEEv
1052 template void fun2
<S1
<int>, int>();
1053 // CHECK-LABEL: @_ZN6test514fun2I2S1IiEiEEDTcldtcvT__Edn2S1IT0_EEEv
1054 template void fun3
<S1
<int>, int>();
1055 // CHECK-LABEL: @_ZN6test514fun3I2S1IiEiEEDTcldtcvS1_IT0_E_EdnT_EEv
1056 template void fun4
<int>();
1057 // CHECK-LABEL: @_ZN6test514fun4IiEEDTcmcldtcv2S1IT_E_Edn2S1IS2_EEcldtcvS3__Edn2S1IS2_EEEv
1058 template void fun5
<int>();
1059 // CHECK-LABEL: @_ZN6test514fun5IiEEDTcldtcv2S1IiE_Edn2S1IT_EEEv
1060 template void fun6
<S1
>();
1061 // CHECK-LABEL: @_ZN6test514fun6I2S1EEDTcldtcvS1_IiE_EdnT_IiEEEv
1062 template void fun7
<E
>();
1063 // CHECK-LABEL: @_ZN6test514fun7INS_1EEEEDTcldtcvS1__Esr1EEdnT_EEv
1064 template void fun8
<X
>();
1070 template <typename
... T
>
1071 auto f4(T
... x
) -> decltype(operator+(x
...));
1072 // CHECK-LABEL: @_ZN6test522f4IJNS_1XEEEEDTclonplspfp_EEDpT_
1073 void use() { f4(X
{}); }
1078 using t1
= struct { int z
; };
1079 using t2
= struct { double z
; };
1080 using t3
= struct { float z
; };
1081 using t4
= struct { float z
; };
1083 __attribute__((used
)) c(t1
) {}
1084 __attribute__((used
)) c(t2
) {}
1085 __attribute__((used
)) c(t3
) {}
1086 __attribute__((used
)) c(t4
) {}
1087 // CHECK-LABEL: @_ZN6test531cC2ENS0_2t1E
1088 // CHECK-LABEL: @_ZN6test531cC2ENS0_2t2E
1089 // CHECK-LABEL: @_ZN6test531cC2ENS0_2t3E
1090 // CHECK-LABEL: @_ZN6test531cC2ENS0_2t4E
1096 using t1
= struct { int z
; } *;
1097 using t2
= struct { double z
; } *;
1099 __attribute__((used
)) c(t1
) {}
1100 __attribute__((used
)) c(t2
) {}
1101 // CHECK-LABEL: @_ZN6test541cC2EPNS0_Ut_E
1102 // CHECK-LABEL: @_ZN6test541cC2EPNS0_Ut0_E
1109 template <typename T
>
1110 void f1(T
, __underlying_type(T
)) {}
1111 template void f1
<E
>(E
, __underlying_type(E
));
1112 // CHECK-LABEL: @_ZN6test552f1INS_1EEEEvT_u17__underlying_typeIS2_E
1114 template <typename T
> void f2(T
, __add_lvalue_reference(T
)) {}
1115 template void f2
<int>(int, __add_lvalue_reference(int));
1116 // CHECK-LABEL: @_ZN6test552f2IiEEvT_u22__add_lvalue_referenceIS1_E
1118 template <typename T
> void f3(T
, __add_pointer(T
)) {}
1119 template void f3
<int>(int, __add_pointer(int));
1120 // CHECK-LABEL: @_ZN6test552f3IiEEvT_u13__add_pointerIS1_E
1122 template <typename T
> void f4(T
, __add_rvalue_reference(T
)) {}
1123 template void f4
<int>(int, __add_rvalue_reference(int));
1124 // CHECK-LABEL: @_ZN6test552f4IiEEvT_u22__add_rvalue_referenceIS1_E
1126 template <typename T
> void f5(T
, __decay(T
)) {}
1127 template void f5
<int>(int, __decay(int));
1128 // CHECK-LABEL: @_ZN6test552f5IiEEvT_u7__decayIS1_E
1130 template <typename T
> void f6(T
, __make_signed(T
)) {}
1131 template void f6
<int>(int, __make_signed(int));
1132 // CHECK-LABEL: @_ZN6test552f6IiEEvT_u13__make_signedIS1_E
1134 template <typename T
> void f7(T
, __make_unsigned(T
)) {}
1135 template void f7
<int>(int, __make_unsigned(int));
1136 // CHECK-LABEL: @_ZN6test552f7IiEEvT_u15__make_unsignedIS1_E
1138 template <typename T
> void f8(T
, __remove_const(T
)) {}
1139 template void f8
<int>(int, __remove_const(int));
1140 // CHECK-LABEL: @_ZN6test552f8IiEEvT_u14__remove_constIS1_E
1142 template <typename T
> void f9(T
, __remove_cv(T
)) {}
1143 template void f9
<int>(int, __remove_cv(int));
1144 // CHECK-LABEL: @_ZN6test552f9IiEEvT_u11__remove_cvIS1_E
1146 template <typename T
> void f10(T
, __remove_cvref(T
)) {}
1147 template void f10
<int>(int, __remove_cvref(int));
1148 // CHECK-LABEL: @_ZN6test553f10IiEEvT_u14__remove_cvrefIS1_E
1150 template <typename T
> void f11(T
, __remove_volatile(T
)) {}
1151 template void f11
<int>(int, __remove_volatile(int));
1152 // CHECK-LABEL: @_ZN6test553f11IiEEvT_u17__remove_volatileIS1_E
1154 template <typename T
> void f12(T
, __remove_extent(T
)) {}
1155 template void f12
<int>(int, __remove_extent(int));
1156 // CHECK-LABEL: @_ZN6test553f12IiEEvT_u15__remove_extentIS1_E
1158 template <typename T
> void f13(T
, __remove_all_extents(T
)) {}
1159 template void f13
<int>(int, __remove_all_extents(int));
1160 // CHECK-LABEL: @_ZN6test553f13IiEEvT_u20__remove_all_extentsIS1_E
1162 template <typename T
> void f14(T
, __remove_pointer(T
)) {}
1163 template void f14
<int>(int, __remove_pointer(int));
1164 // CHECK-LABEL: @_ZN6test553f14IiEEvT_u16__remove_pointerIS1_E
1166 template <typename T
> void f15(T
, __remove_reference_t(T
)) {}
1167 template void f15
<int>(int, __remove_reference_t(int));
1168 // CHECK-LABEL: @_ZN6test553f15IiEEvT_u20__remove_reference_tIS1_E
1170 template <typename T
> void f16(T
, __remove_volatile(T
)) {}
1171 template void f16
<int>(int, __remove_volatile(int));
1172 // CHECK-LABEL: @_ZN6test553f16IiEEvT_u17__remove_volatileIS1_E
1174 template <typename T
> void f17(T
, __remove_restrict(T
)) {}
1175 template void f17
<int>(int, __remove_restrict(int));
1176 // CHECK-LABEL: @_ZN6test553f17IiEEvT_u17__remove_restrictIS1_E
1177 } // namespace test55
1180 struct A
{ A
*operator->(); int n
; } a
;
1181 template<int N
> void f(decltype(a
->n
+ N
)) {}
1182 // CHECK-LABEL: @_ZN6test561fILi0EEEvDTplptL_ZNS_1aEE1nT_E
1183 template void f
<0>(int);
1187 struct X
{ template <int N
> int f(); } x
;
1188 template<int N
> void f(decltype(x
.f
<0>() + N
)) {}
1189 // CHECK-LABEL: @_ZN6test571fILi0EEEvDTplcldtL_ZNS_1xEE1fILi0EEET_E
1190 template void f
<0>(int);
1197 template <class T
> struct identity
{ typedef T type
; };
1199 template <typename T
> A(T
, bool (identity
<T
>::type::*)());
1201 // CHECK-LABEL: @_ZN6test581AC1INS_5StateEEET_MNS_8identityIS3_E4typeEFbvE
1202 void fn1() { A(a
, &State::m_fn1
); }
1207 template<typename T
>
1215 struct X
{ int i
, j
; };
1216 auto [a
,b
] = X
{1,2};
1217 template<typename T
> void f(decltype(a
+ T())) {}
1218 // CHECK-LABEL: @_ZN6test601fIiEEvDTplL_ZNS_1aEEcvT__EE
1219 template void f
<int>(int);
1229 template <typename T
> void f(typename
T::Y::a
, typename
T::Y::b
) {}
1230 // CHECK-LABEL: @_ZN6test611fINS_1XEEEvNT_1Y1aENS3_1bE
1231 template void f
<X
>(int, int);