xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/mangle-exprs.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc namespace std {
4*f4a2713aSLionel Sambuc   typedef decltype(sizeof(int)) size_t;
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc   // libc++'s implementation
7*f4a2713aSLionel Sambuc   template <class _E>
8*f4a2713aSLionel Sambuc   class initializer_list
9*f4a2713aSLionel Sambuc   {
10*f4a2713aSLionel Sambuc     const _E* __begin_;
11*f4a2713aSLionel Sambuc     size_t    __size_;
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc     initializer_list(const _E* __b, size_t __s)
14*f4a2713aSLionel Sambuc       : __begin_(__b),
15*f4a2713aSLionel Sambuc         __size_(__s)
16*f4a2713aSLionel Sambuc     {}
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc   public:
19*f4a2713aSLionel Sambuc     typedef _E        value_type;
20*f4a2713aSLionel Sambuc     typedef const _E& reference;
21*f4a2713aSLionel Sambuc     typedef const _E& const_reference;
22*f4a2713aSLionel Sambuc     typedef size_t    size_type;
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc     typedef const _E* iterator;
25*f4a2713aSLionel Sambuc     typedef const _E* const_iterator;
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc     initializer_list() : __begin_(nullptr), __size_(0) {}
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc     size_t    size()  const {return __size_;}
30*f4a2713aSLionel Sambuc     const _E* begin() const {return __begin_;}
31*f4a2713aSLionel Sambuc     const _E* end()   const {return __begin_ + __size_;}
32*f4a2713aSLionel Sambuc   };
33*f4a2713aSLionel Sambuc }
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc template < bool condition, typename T = void >
36*f4a2713aSLionel Sambuc struct enable_if { typedef T type; };
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc template< typename T >
39*f4a2713aSLionel Sambuc struct enable_if< false, T > {};
40*f4a2713aSLionel Sambuc 
41*f4a2713aSLionel Sambuc // PR5876
42*f4a2713aSLionel Sambuc namespace Casts {
43*f4a2713aSLionel Sambuc   template< unsigned O >
44*f4a2713aSLionel Sambuc   void implicit(typename enable_if< O <= 4 >::type* = 0) {
45*f4a2713aSLionel Sambuc   }
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc   template< unsigned O >
48*f4a2713aSLionel Sambuc   void cstyle(typename enable_if< O <= (unsigned)4 >::type* = 0) {
49*f4a2713aSLionel Sambuc   }
50*f4a2713aSLionel Sambuc 
51*f4a2713aSLionel Sambuc   template< unsigned O >
52*f4a2713aSLionel Sambuc   void functional(typename enable_if< O <= unsigned(4) >::type* = 0) {
53*f4a2713aSLionel Sambuc   }
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc   template< unsigned O >
56*f4a2713aSLionel Sambuc   void static_(typename enable_if< O <= static_cast<unsigned>(4) >::type* = 0) {
57*f4a2713aSLionel Sambuc   }
58*f4a2713aSLionel Sambuc 
59*f4a2713aSLionel Sambuc   template< typename T >
60*f4a2713aSLionel Sambuc   void auto_(decltype(new auto(T()))) {
61*f4a2713aSLionel Sambuc   }
62*f4a2713aSLionel Sambuc 
63*f4a2713aSLionel Sambuc   template< typename T >
64*f4a2713aSLionel Sambuc   void scalar_(decltype(T(), int())) {
65*f4a2713aSLionel Sambuc   }
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc   // FIXME: Test const_cast, reinterpret_cast, dynamic_cast, which are
68*f4a2713aSLionel Sambuc   // a bit harder to use in template arguments.
69*f4a2713aSLionel Sambuc   template <unsigned N> struct T {};
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc   template <int N> T<N> f() { return T<N>(); }
72*f4a2713aSLionel Sambuc 
73*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts8implicitILj4EEEvPN9enable_ifIXleT_Li4EEvE4typeE
74*f4a2713aSLionel Sambuc   template void implicit<4>(void*);
75*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts6cstyleILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
76*f4a2713aSLionel Sambuc   template void cstyle<4>(void*);
77*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts10functionalILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
78*f4a2713aSLionel Sambuc   template void functional<4>(void*);
79*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
80*f4a2713aSLionel Sambuc   template void static_<4>(void*);
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts1fILi6EEENS_1TIXT_EEEv
83*f4a2713aSLionel Sambuc   template T<6> f<6>();
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts5auto_IiEEvDTnw_DapicvT__EEE(
86*f4a2713aSLionel Sambuc   template void auto_<int>(int*);
87*f4a2713aSLionel Sambuc 
88*f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts7scalar_IiEEvDTcmcvT__Ecvi_EE(
89*f4a2713aSLionel Sambuc   template void scalar_<int>(int);
90*f4a2713aSLionel Sambuc }
91*f4a2713aSLionel Sambuc 
92*f4a2713aSLionel Sambuc namespace test1 {
93*f4a2713aSLionel Sambuc   short foo(short);
94*f4a2713aSLionel Sambuc   int foo(int);
95*f4a2713aSLionel Sambuc 
96*f4a2713aSLionel Sambuc   // CHECK-LABEL: define linkonce_odr signext i16 @_ZN5test11aIsEEDTcl3foocvT__EEES1_(
97*f4a2713aSLionel Sambuc   template <class T> auto a(T t) -> decltype(foo(T())) { return foo(t); }
98*f4a2713aSLionel Sambuc 
99*f4a2713aSLionel Sambuc   // CHECK-LABEL: define linkonce_odr signext i16 @_ZN5test11bIsEEDTcp3foocvT__EEES1_(
100*f4a2713aSLionel Sambuc   template <class T> auto b(T t) -> decltype((foo)(T())) { return (foo)(t); }
101*f4a2713aSLionel Sambuc 
102*f4a2713aSLionel Sambuc   void test(short s) {
103*f4a2713aSLionel Sambuc     a(s);
104*f4a2713aSLionel Sambuc     b(s);
105*f4a2713aSLionel Sambuc   }
106*f4a2713aSLionel Sambuc }
107*f4a2713aSLionel Sambuc 
108*f4a2713aSLionel Sambuc namespace test2 {
109*f4a2713aSLionel Sambuc   template <class T> void a(T x, decltype(x()) y) {}
110*f4a2713aSLionel Sambuc   template <class T> auto b(T x) -> decltype(x()) { return x(); }
111*f4a2713aSLionel Sambuc   template <class T> void c(T x, void (*p)(decltype(x()))) {}
112*f4a2713aSLionel Sambuc   template <class T> void d(T x, auto (*p)() -> decltype(x())) {}
113*f4a2713aSLionel Sambuc   template <class T> void e(auto (*p)(T y) -> decltype(y())) {}
114*f4a2713aSLionel Sambuc   template <class T> void f(void (*p)(T x, decltype(x()) y)) {}
115*f4a2713aSLionel Sambuc   template <class T> void g(T x, decltype(x()) y) {
116*f4a2713aSLionel Sambuc     static decltype(x()) variable;
117*f4a2713aSLionel Sambuc     variable = 0;
118*f4a2713aSLionel Sambuc   }
119*f4a2713aSLionel Sambuc   template <class T> void h(T x, decltype((decltype(x())(*)()) 0) y) {}
120*f4a2713aSLionel Sambuc   template <class T> void i(decltype((auto (*)(T x) -> decltype(x())) 0) y) {}
121*f4a2713aSLionel Sambuc 
122*f4a2713aSLionel Sambuc   float foo();
123*f4a2713aSLionel Sambuc   void bar(float);
124*f4a2713aSLionel Sambuc   float baz(float(*)());
125*f4a2713aSLionel Sambuc   void fred(float(*)(), float);
126*f4a2713aSLionel Sambuc 
127*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test211instantiateEv
128*f4a2713aSLionel Sambuc   void instantiate() {
129*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21aIPFfvEEEvT_DTclfL0p_EE(
130*f4a2713aSLionel Sambuc     a(foo, 0.0f);
131*f4a2713aSLionel Sambuc     // CHECK: call float @_ZN5test21bIPFfvEEEDTclfp_EET_(
132*f4a2713aSLionel Sambuc     (void) b(foo);
133*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21cIPFfvEEEvT_PFvDTclfL1p_EEE(
134*f4a2713aSLionel Sambuc     c(foo, bar);
135*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21dIPFfvEEEvT_PFDTclfL0p_EEvE(
136*f4a2713aSLionel Sambuc     d(foo, foo);
137*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21eIPFfvEEEvPFDTclfp_EET_E(
138*f4a2713aSLionel Sambuc     e(baz);
139*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21fIPFfvEEEvPFvT_DTclfL0p_EEE(
140*f4a2713aSLionel Sambuc     f(fred);
141*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21gIPFfvEEEvT_DTclfL0p_EE(
142*f4a2713aSLionel Sambuc     g(foo, 0.0f);
143*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21hIPFfvEEEvT_DTcvPFDTclfL0p_EEvELi0EE(
144*f4a2713aSLionel Sambuc     h(foo, foo);
145*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21iIPFfvEEEvDTcvPFDTclfp_EET_ELi0EE(
146*f4a2713aSLionel Sambuc     i<float(*)()>(baz);
147*f4a2713aSLionel Sambuc   }
148*f4a2713aSLionel Sambuc 
149*f4a2713aSLionel Sambuc   // CHECK: store float {{.*}}, float* @_ZZN5test21gIPFfvEEEvT_DTclfL0p_EEE8variable,
150*f4a2713aSLionel Sambuc }
151*f4a2713aSLionel Sambuc 
152*f4a2713aSLionel Sambuc namespace test3 {
153*f4a2713aSLionel Sambuc   template <class T, class U> void a(T x, U y, decltype(x.*y) z) {}
154*f4a2713aSLionel Sambuc 
155*f4a2713aSLionel Sambuc   struct X {
156*f4a2713aSLionel Sambuc     int *member;
157*f4a2713aSLionel Sambuc   };
158*f4a2713aSLionel Sambuc 
159*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test311instantiateEv
160*f4a2713aSLionel Sambuc   void instantiate() {
161*f4a2713aSLionel Sambuc     X x;
162*f4a2713aSLionel Sambuc     int *ip;
163*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test31aINS_1XEMS1_PiEEvT_T0_DTdsfL0p_fL0p0_E
164*f4a2713aSLionel Sambuc     a(x, &X::member, ip);
165*f4a2713aSLionel Sambuc   }
166*f4a2713aSLionel Sambuc }
167*f4a2713aSLionel Sambuc 
168*f4a2713aSLionel Sambuc namespace test4 {
169*f4a2713aSLionel Sambuc   struct X {
170*f4a2713aSLionel Sambuc     X(int);
171*f4a2713aSLionel Sambuc   };
172*f4a2713aSLionel Sambuc 
173*f4a2713aSLionel Sambuc   template <typename T>
174*f4a2713aSLionel Sambuc   void tf1(decltype(new T(1)) p)
175*f4a2713aSLionel Sambuc   {}
176*f4a2713aSLionel Sambuc 
177*f4a2713aSLionel Sambuc   template <typename T>
178*f4a2713aSLionel Sambuc   void tf2(decltype(new T({1})) p)
179*f4a2713aSLionel Sambuc   {}
180*f4a2713aSLionel Sambuc 
181*f4a2713aSLionel Sambuc   template <typename T>
182*f4a2713aSLionel Sambuc   void tf3(decltype(new T{1}) p)
183*f4a2713aSLionel Sambuc   {}
184*f4a2713aSLionel Sambuc 
185*f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test43tf1INS_1XEEEvDTnw_T_piLi1EEE
186*f4a2713aSLionel Sambuc   template void tf1<X>(X*);
187*f4a2713aSLionel Sambuc 
188*f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test43tf2INS_1XEEEvDTnw_T_piilLi1EEEE
189*f4a2713aSLionel Sambuc   template void tf2<X>(X*);
190*f4a2713aSLionel Sambuc 
191*f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test43tf3INS_1XEEEvDTnw_T_ilLi1EEE
192*f4a2713aSLionel Sambuc   template void tf3<X>(X*);
193*f4a2713aSLionel Sambuc 
194*f4a2713aSLionel Sambuc }
195*f4a2713aSLionel Sambuc 
196*f4a2713aSLionel Sambuc namespace test5 {
197*f4a2713aSLionel Sambuc   template <typename T> void a(decltype(noexcept(T()))) {}
198*f4a2713aSLionel Sambuc   template void a<int>(decltype(noexcept(int())));
199*f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test51aIiEEvDTnxcvT__EE(
200*f4a2713aSLionel Sambuc }
201