xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/mangle-exprs.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc namespace std {
4f4a2713aSLionel Sambuc   typedef decltype(sizeof(int)) size_t;
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc   // libc++'s implementation
7f4a2713aSLionel Sambuc   template <class _E>
8f4a2713aSLionel Sambuc   class initializer_list
9f4a2713aSLionel Sambuc   {
10f4a2713aSLionel Sambuc     const _E* __begin_;
11f4a2713aSLionel Sambuc     size_t    __size_;
12f4a2713aSLionel Sambuc 
initializer_list(const _E * __b,size_t __s)13f4a2713aSLionel Sambuc     initializer_list(const _E* __b, size_t __s)
14f4a2713aSLionel Sambuc       : __begin_(__b),
15f4a2713aSLionel Sambuc         __size_(__s)
16f4a2713aSLionel Sambuc     {}
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc   public:
19f4a2713aSLionel Sambuc     typedef _E        value_type;
20f4a2713aSLionel Sambuc     typedef const _E& reference;
21f4a2713aSLionel Sambuc     typedef const _E& const_reference;
22f4a2713aSLionel Sambuc     typedef size_t    size_type;
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc     typedef const _E* iterator;
25f4a2713aSLionel Sambuc     typedef const _E* const_iterator;
26f4a2713aSLionel Sambuc 
initializer_list()27f4a2713aSLionel Sambuc     initializer_list() : __begin_(nullptr), __size_(0) {}
28f4a2713aSLionel Sambuc 
size() const29f4a2713aSLionel Sambuc     size_t    size()  const {return __size_;}
begin() const30f4a2713aSLionel Sambuc     const _E* begin() const {return __begin_;}
end() const31f4a2713aSLionel Sambuc     const _E* end()   const {return __begin_ + __size_;}
32f4a2713aSLionel Sambuc   };
33f4a2713aSLionel Sambuc }
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc template < bool condition, typename T = void >
36f4a2713aSLionel Sambuc struct enable_if { typedef T type; };
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc template< typename T >
39f4a2713aSLionel Sambuc struct enable_if< false, T > {};
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc // PR5876
42f4a2713aSLionel Sambuc namespace Casts {
43f4a2713aSLionel Sambuc   template< unsigned O >
implicit(typename enable_if<O<=4>::type * =0)44f4a2713aSLionel Sambuc   void implicit(typename enable_if< O <= 4 >::type* = 0) {
45f4a2713aSLionel Sambuc   }
46f4a2713aSLionel Sambuc 
47f4a2713aSLionel Sambuc   template< unsigned O >
cstyle(typename enable_if<O<=(unsigned)4>::type * =0)48f4a2713aSLionel Sambuc   void cstyle(typename enable_if< O <= (unsigned)4 >::type* = 0) {
49f4a2713aSLionel Sambuc   }
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc   template< unsigned O >
functional(typename enable_if<O<=unsigned (4)>::type * =0)52f4a2713aSLionel Sambuc   void functional(typename enable_if< O <= unsigned(4) >::type* = 0) {
53f4a2713aSLionel Sambuc   }
54f4a2713aSLionel Sambuc 
55f4a2713aSLionel Sambuc   template< unsigned O >
static_(typename enable_if<O<=static_cast<unsigned> (4)>::type * =0)56f4a2713aSLionel Sambuc   void static_(typename enable_if< O <= static_cast<unsigned>(4) >::type* = 0) {
57f4a2713aSLionel Sambuc   }
58f4a2713aSLionel Sambuc 
59*0a6a1f1dSLionel Sambuc   template <unsigned O, typename T>
reinterpret_(typename enable_if<O<=sizeof (reinterpret_cast<T * > (0))>::type * =0)60*0a6a1f1dSLionel Sambuc   void reinterpret_(typename enable_if<O <= sizeof(reinterpret_cast<T *>(0))>::type * = 0) {
61*0a6a1f1dSLionel Sambuc   }
62*0a6a1f1dSLionel Sambuc 
63*0a6a1f1dSLionel Sambuc   template <typename T, T *p>
const_(typename enable_if<0<=sizeof (const_cast<T * > (p))>::type * =0)64*0a6a1f1dSLionel Sambuc   void const_(typename enable_if<0 <= sizeof(const_cast<T *>(p))>::type * = 0) {
65*0a6a1f1dSLionel Sambuc   }
66*0a6a1f1dSLionel Sambuc 
67*0a6a1f1dSLionel Sambuc   template <typename T, T *p>
dynamic_(typename enable_if<0<=sizeof (dynamic_cast<T * > (p))>::type * =0)68*0a6a1f1dSLionel Sambuc   void dynamic_(typename enable_if<0 <= sizeof(dynamic_cast<T *>(p))>::type * = 0) {
69*0a6a1f1dSLionel Sambuc   }
70*0a6a1f1dSLionel Sambuc 
71f4a2713aSLionel Sambuc   template< typename T >
auto_(decltype(new auto (T ())) )72f4a2713aSLionel Sambuc   void auto_(decltype(new auto(T()))) {
73f4a2713aSLionel Sambuc   }
74f4a2713aSLionel Sambuc 
75f4a2713aSLionel Sambuc   template< typename T >
scalar_(decltype(T (),int ()) )76f4a2713aSLionel Sambuc   void scalar_(decltype(T(), int())) {
77f4a2713aSLionel Sambuc   }
78f4a2713aSLionel Sambuc 
79f4a2713aSLionel Sambuc   template <unsigned N> struct T {};
80f4a2713aSLionel Sambuc 
f()81f4a2713aSLionel Sambuc   template <int N> T<N> f() { return T<N>(); }
82f4a2713aSLionel Sambuc 
83*0a6a1f1dSLionel Sambuc   extern int i;
84*0a6a1f1dSLionel Sambuc   extern struct S {} s;
85*0a6a1f1dSLionel Sambuc 
86f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts8implicitILj4EEEvPN9enable_ifIXleT_Li4EEvE4typeE
87f4a2713aSLionel Sambuc   template void implicit<4>(void*);
88f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts6cstyleILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
89f4a2713aSLionel Sambuc   template void cstyle<4>(void*);
90f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts10functionalILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
91f4a2713aSLionel Sambuc   template void functional<4>(void*);
92*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_scjLi4EEvE4typeE
93f4a2713aSLionel Sambuc   template void static_<4>(void*);
94*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts12reinterpret_ILj4EiEEvPN9enable_ifIXleT_szrcPT0_Li0EEvE4typeE
95*0a6a1f1dSLionel Sambuc   template void reinterpret_<4, int>(void*);
96*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts6const_IiXadL_ZNS_1iEEEEEvPN9enable_ifIXleLi0EszccPT_T0_EvE4typeE
97*0a6a1f1dSLionel Sambuc   template void const_<int, &i>(void*);
98*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts8dynamic_INS_1SEXadL_ZNS_1sEEEEEvPN9enable_ifIXleLi0EszdcPT_T0_EvE4typeE
99*0a6a1f1dSLionel Sambuc   template void dynamic_<struct S, &s>(void*);
100f4a2713aSLionel Sambuc 
101f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts1fILi6EEENS_1TIXT_EEEv
102f4a2713aSLionel Sambuc   template T<6> f<6>();
103f4a2713aSLionel Sambuc 
104f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts5auto_IiEEvDTnw_DapicvT__EEE(
105f4a2713aSLionel Sambuc   template void auto_<int>(int*);
106f4a2713aSLionel Sambuc 
107f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5Casts7scalar_IiEEvDTcmcvT__Ecvi_EE(
108f4a2713aSLionel Sambuc   template void scalar_<int>(int);
109f4a2713aSLionel Sambuc }
110f4a2713aSLionel Sambuc 
111f4a2713aSLionel Sambuc namespace test1 {
112f4a2713aSLionel Sambuc   short foo(short);
113f4a2713aSLionel Sambuc   int foo(int);
114f4a2713aSLionel Sambuc 
115f4a2713aSLionel Sambuc   // CHECK-LABEL: define linkonce_odr signext i16 @_ZN5test11aIsEEDTcl3foocvT__EEES1_(
a(T t)116f4a2713aSLionel Sambuc   template <class T> auto a(T t) -> decltype(foo(T())) { return foo(t); }
117f4a2713aSLionel Sambuc 
118f4a2713aSLionel Sambuc   // CHECK-LABEL: define linkonce_odr signext i16 @_ZN5test11bIsEEDTcp3foocvT__EEES1_(
b(T t)119f4a2713aSLionel Sambuc   template <class T> auto b(T t) -> decltype((foo)(T())) { return (foo)(t); }
120f4a2713aSLionel Sambuc 
test(short s)121f4a2713aSLionel Sambuc   void test(short s) {
122f4a2713aSLionel Sambuc     a(s);
123f4a2713aSLionel Sambuc     b(s);
124f4a2713aSLionel Sambuc   }
125f4a2713aSLionel Sambuc }
126f4a2713aSLionel Sambuc 
127f4a2713aSLionel Sambuc namespace test2 {
a(T x,decltype(x ()) y)128f4a2713aSLionel Sambuc   template <class T> void a(T x, decltype(x()) y) {}
b(T x)129f4a2713aSLionel Sambuc   template <class T> auto b(T x) -> decltype(x()) { return x(); }
c(T x,void (* p)(decltype(x ()) ))130f4a2713aSLionel Sambuc   template <class T> void c(T x, void (*p)(decltype(x()))) {}
131f4a2713aSLionel Sambuc   template <class T> void d(T x, auto (*p)() -> decltype(x())) {}
132f4a2713aSLionel Sambuc   template <class T> void e(auto (*p)(T y) -> decltype(y())) {}
f(void (* p)(T x,decltype(x ()) y))133f4a2713aSLionel Sambuc   template <class T> void f(void (*p)(T x, decltype(x()) y)) {}
g(T x,decltype(x ()) y)134f4a2713aSLionel Sambuc   template <class T> void g(T x, decltype(x()) y) {
135f4a2713aSLionel Sambuc     static decltype(x()) variable;
136f4a2713aSLionel Sambuc     variable = 0;
137f4a2713aSLionel Sambuc   }
138f4a2713aSLionel Sambuc   template <class T> void h(T x, decltype((decltype(x())(*)()) 0) y) {}
139f4a2713aSLionel Sambuc   template <class T> void i(decltype((auto (*)(T x) -> decltype(x())) 0) y) {}
140f4a2713aSLionel Sambuc 
141f4a2713aSLionel Sambuc   float foo();
142f4a2713aSLionel Sambuc   void bar(float);
143f4a2713aSLionel Sambuc   float baz(float(*)());
144f4a2713aSLionel Sambuc   void fred(float(*)(), float);
145f4a2713aSLionel Sambuc 
146f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test211instantiateEv
instantiate()147f4a2713aSLionel Sambuc   void instantiate() {
148f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21aIPFfvEEEvT_DTclfL0p_EE(
149f4a2713aSLionel Sambuc     a(foo, 0.0f);
150f4a2713aSLionel Sambuc     // CHECK: call float @_ZN5test21bIPFfvEEEDTclfp_EET_(
151f4a2713aSLionel Sambuc     (void) b(foo);
152f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21cIPFfvEEEvT_PFvDTclfL1p_EEE(
153f4a2713aSLionel Sambuc     c(foo, bar);
154f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21dIPFfvEEEvT_PFDTclfL0p_EEvE(
155f4a2713aSLionel Sambuc     d(foo, foo);
156f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21eIPFfvEEEvPFDTclfp_EET_E(
157f4a2713aSLionel Sambuc     e(baz);
158f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21fIPFfvEEEvPFvT_DTclfL0p_EEE(
159f4a2713aSLionel Sambuc     f(fred);
160f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21gIPFfvEEEvT_DTclfL0p_EE(
161f4a2713aSLionel Sambuc     g(foo, 0.0f);
162f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21hIPFfvEEEvT_DTcvPFDTclfL0p_EEvELi0EE(
163f4a2713aSLionel Sambuc     h(foo, foo);
164f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test21iIPFfvEEEvDTcvPFDTclfp_EET_ELi0EE(
165f4a2713aSLionel Sambuc     i<float(*)()>(baz);
166f4a2713aSLionel Sambuc   }
167f4a2713aSLionel Sambuc 
168f4a2713aSLionel Sambuc   // CHECK: store float {{.*}}, float* @_ZZN5test21gIPFfvEEEvT_DTclfL0p_EEE8variable,
169f4a2713aSLionel Sambuc }
170f4a2713aSLionel Sambuc 
171f4a2713aSLionel Sambuc namespace test3 {
172f4a2713aSLionel Sambuc   template <class T, class U> void a(T x, U y, decltype(x.*y) z) {}
173f4a2713aSLionel Sambuc 
174f4a2713aSLionel Sambuc   struct X {
175f4a2713aSLionel Sambuc     int *member;
176f4a2713aSLionel Sambuc   };
177f4a2713aSLionel Sambuc 
178f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test311instantiateEv
instantiate()179f4a2713aSLionel Sambuc   void instantiate() {
180f4a2713aSLionel Sambuc     X x;
181f4a2713aSLionel Sambuc     int *ip;
182f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test31aINS_1XEMS1_PiEEvT_T0_DTdsfL0p_fL0p0_E
183f4a2713aSLionel Sambuc     a(x, &X::member, ip);
184f4a2713aSLionel Sambuc   }
185f4a2713aSLionel Sambuc }
186f4a2713aSLionel Sambuc 
187f4a2713aSLionel Sambuc namespace test4 {
188f4a2713aSLionel Sambuc   struct X {
189f4a2713aSLionel Sambuc     X(int);
190f4a2713aSLionel Sambuc   };
191f4a2713aSLionel Sambuc 
192f4a2713aSLionel Sambuc   template <typename T>
193f4a2713aSLionel Sambuc   void tf1(decltype(new T(1)) p)
194f4a2713aSLionel Sambuc   {}
195f4a2713aSLionel Sambuc 
196f4a2713aSLionel Sambuc   template <typename T>
197f4a2713aSLionel Sambuc   void tf2(decltype(new T({1})) p)
198f4a2713aSLionel Sambuc   {}
199f4a2713aSLionel Sambuc 
200f4a2713aSLionel Sambuc   template <typename T>
tf3(decltype(new T{1}) p)201f4a2713aSLionel Sambuc   void tf3(decltype(new T{1}) p)
202f4a2713aSLionel Sambuc   {}
203f4a2713aSLionel Sambuc 
204f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test43tf1INS_1XEEEvDTnw_T_piLi1EEE
205f4a2713aSLionel Sambuc   template void tf1<X>(X*);
206f4a2713aSLionel Sambuc 
207f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test43tf2INS_1XEEEvDTnw_T_piilLi1EEEE
208f4a2713aSLionel Sambuc   template void tf2<X>(X*);
209f4a2713aSLionel Sambuc 
210f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test43tf3INS_1XEEEvDTnw_T_ilLi1EEE
211f4a2713aSLionel Sambuc   template void tf3<X>(X*);
212f4a2713aSLionel Sambuc 
213f4a2713aSLionel Sambuc }
214f4a2713aSLionel Sambuc 
215f4a2713aSLionel Sambuc namespace test5 {
a(decltype(noexcept (T ())) )216f4a2713aSLionel Sambuc   template <typename T> void a(decltype(noexcept(T()))) {}
217f4a2713aSLionel Sambuc   template void a<int>(decltype(noexcept(int())));
218f4a2713aSLionel Sambuc   // CHECK: void @_ZN5test51aIiEEvDTnxcvT__EE(
219f4a2713aSLionel Sambuc }
220*0a6a1f1dSLionel Sambuc 
221*0a6a1f1dSLionel Sambuc namespace test6 {
222*0a6a1f1dSLionel Sambuc   struct X {
223*0a6a1f1dSLionel Sambuc     int i;
224*0a6a1f1dSLionel Sambuc   };
225*0a6a1f1dSLionel Sambuc 
226*0a6a1f1dSLionel Sambuc   struct Y {
227*0a6a1f1dSLionel Sambuc     union {
228*0a6a1f1dSLionel Sambuc       int i;
229*0a6a1f1dSLionel Sambuc     };
230*0a6a1f1dSLionel Sambuc   };
231*0a6a1f1dSLionel Sambuc 
232*0a6a1f1dSLionel Sambuc   struct Z {
233*0a6a1f1dSLionel Sambuc     union {
234*0a6a1f1dSLionel Sambuc       X ua;
235*0a6a1f1dSLionel Sambuc       Y ub;
236*0a6a1f1dSLionel Sambuc     };
237*0a6a1f1dSLionel Sambuc 
238*0a6a1f1dSLionel Sambuc     struct {
239*0a6a1f1dSLionel Sambuc       X s;
240*0a6a1f1dSLionel Sambuc     };
241*0a6a1f1dSLionel Sambuc 
242*0a6a1f1dSLionel Sambuc     union {
243*0a6a1f1dSLionel Sambuc       union {
244*0a6a1f1dSLionel Sambuc         struct {
245*0a6a1f1dSLionel Sambuc           struct {
246*0a6a1f1dSLionel Sambuc             X uuss;
247*0a6a1f1dSLionel Sambuc           };
248*0a6a1f1dSLionel Sambuc         };
249*0a6a1f1dSLionel Sambuc       };
250*0a6a1f1dSLionel Sambuc     };
251*0a6a1f1dSLionel Sambuc   };
252*0a6a1f1dSLionel Sambuc 
253*0a6a1f1dSLionel Sambuc   Z z, *zp;
254*0a6a1f1dSLionel Sambuc 
255*0a6a1f1dSLionel Sambuc   template<typename T>
256*0a6a1f1dSLionel Sambuc   void f1(decltype(T(z.ua.i))) {}
257*0a6a1f1dSLionel Sambuc   template void f1<int>(int);
258*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test62f1IiEEvDTcvT_dtdtL_ZNS_1zEE2ua1iE
259*0a6a1f1dSLionel Sambuc 
260*0a6a1f1dSLionel Sambuc   template<typename T>
261*0a6a1f1dSLionel Sambuc   void f2(decltype(T(z.ub.i))) {}
262*0a6a1f1dSLionel Sambuc   template void f2<int>(int);
263*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test62f2IiEEvDTcvT_dtdtL_ZNS_1zEE2ub1iE
264*0a6a1f1dSLionel Sambuc 
265*0a6a1f1dSLionel Sambuc   template<typename T>
266*0a6a1f1dSLionel Sambuc   void f3(decltype(T(z.s.i))) {}
267*0a6a1f1dSLionel Sambuc   template void f3<int>(int);
268*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test62f3IiEEvDTcvT_dtdtL_ZNS_1zEE1s1iE
269*0a6a1f1dSLionel Sambuc 
270*0a6a1f1dSLionel Sambuc   template<typename T>
271*0a6a1f1dSLionel Sambuc   void f4(decltype(T(z.uuss.i))) {}
272*0a6a1f1dSLionel Sambuc   template void f4<int>(int);
273*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test62f4IiEEvDTcvT_dtdtL_ZNS_1zEE4uuss1iE
274*0a6a1f1dSLionel Sambuc 
275*0a6a1f1dSLionel Sambuc   template<typename T>
276*0a6a1f1dSLionel Sambuc   void f5(decltype(T(zp->ua.i))) {}
277*0a6a1f1dSLionel Sambuc   template void f5<int>(int);
278*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test62f5IiEEvDTcvT_dtptL_ZNS_2zpEE2ua1iE
279*0a6a1f1dSLionel Sambuc 
280*0a6a1f1dSLionel Sambuc   template<typename T>
281*0a6a1f1dSLionel Sambuc   void f6(decltype(T(zp->ub.i))) {}
282*0a6a1f1dSLionel Sambuc   template void f6<int>(int);
283*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test62f6IiEEvDTcvT_dtptL_ZNS_2zpEE2ub1iE
284*0a6a1f1dSLionel Sambuc 
285*0a6a1f1dSLionel Sambuc   template<typename T>
286*0a6a1f1dSLionel Sambuc   void f7(decltype(T(zp->s.i))) {}
287*0a6a1f1dSLionel Sambuc   template void f7<int>(int);
288*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test62f7IiEEvDTcvT_dtptL_ZNS_2zpEE1s1iE
289*0a6a1f1dSLionel Sambuc 
290*0a6a1f1dSLionel Sambuc   template<typename T>
291*0a6a1f1dSLionel Sambuc   void f8(decltype(T(zp->uuss.i))) {}
292*0a6a1f1dSLionel Sambuc   template void f8<int>(int);
293*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN5test62f8IiEEvDTcvT_dtptL_ZNS_2zpEE4uuss1iE
294*0a6a1f1dSLionel Sambuc }
295*0a6a1f1dSLionel Sambuc 
296