1 | // RUN: %clang_cc1 -verify -Wno-return-type -Wno-main -std=c++11 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s |
2 | // expected-no-diagnostics |
3 | |
4 | namespace test1 { |
5 | int x; |
6 | template <int& D> class T { }; |
7 | // CHECK: void @_ZN5test12f0ENS_1TIL_ZNS_1xEEEE( |
8 | void f0(T<x> a0) {} |
9 | } |
10 | |
11 | namespace test1 { |
12 | // CHECK: void @_ZN5test12f0Ef |
13 | void f0(float) {} |
14 | template<void (&)(float)> struct t1 {}; |
15 | // CHECK: void @_ZN5test12f1ENS_2t1IL_ZNS_2f0EfEEE( |
16 | void f1(t1<f0> a0) {} |
17 | } |
18 | |
19 | namespace test2 { |
20 | // CHECK: void @_ZN5test22f0Ef |
21 | void f0(float) {} |
22 | template<void (*)(float)> struct t1 {}; |
23 | // CHECK: void @_ZN5test22f1ENS_2t1IXadL_ZNS_2f0EfEEEE( |
24 | void f1(t1<f0> a0) {} |
25 | } |
26 | |
27 | namespace test3 { |
28 | // CHECK: void @test3_f0 |
29 | extern "C" void test3_f0(float) {} |
30 | template<void (&)(float)> struct t1 {}; |
31 | // CHECK: void @_ZN5test32f1ENS_2t1IL_Z8test3_f0EEE( |
32 | void f1(t1<test3_f0> a0) {} |
33 | } |
34 | |
35 | namespace test4 { |
36 | // CHECK: void @test4_f0 |
37 | extern "C" void test4_f0(float) {} |
38 | template<void (*)(float)> struct t1 {}; |
39 | // CHECK: void @_ZN5test42f1ENS_2t1IXadL_Z8test4_f0EEEE( |
40 | void f1(t1<test4_f0> a0) {} |
41 | } |
42 | |
43 | // CHECK: void @test5_f0 |
44 | extern "C" void test5_f0(float) {} |
45 | int main(int) {} |
46 | |
47 | namespace test5 { |
48 | template<void (&)(float)> struct t1 {}; |
49 | // CHECK: void @_ZN5test52f1ENS_2t1IL_Z8test5_f0EEE( |
50 | void f1(t1<test5_f0> a0) {} |
51 | |
52 | template<int (&)(int)> struct t2 {}; |
53 | // CHECK: void @_ZN5test52f2ENS_2t2IL_Z4mainEEE |
54 | void f2(t2<main> a0) {} |
55 | } |
56 | |
57 | namespace test6 { |
58 | struct A { void im0(float); }; |
59 | // CHECK: void @_ZN5test61A3im0Ef |
60 | void A::im0(float) {} |
61 | template <void(A::*)(float)> class T { }; |
62 | // CHECK: void @_ZN5test62f0ENS_1TIXadL_ZNS_1A3im0EfEEEE( |
63 | void f0(T<&A::im0> a0) {} |
64 | } |
65 | |
66 | namespace test7 { |
67 | template<typename T> |
68 | struct meta { |
69 | static const unsigned value = sizeof(T); |
70 | }; |
71 | |
72 | template<unsigned> struct int_c { |
73 | typedef float type; |
74 | }; |
75 | |
76 | template<typename T> |
77 | struct X { |
78 | template<typename U> |
79 | X(U*, typename int_c<(meta<T>::value + meta<U>::value)>::type *) { } |
80 | }; |
81 | |
82 | // CHECK: define weak_odr {{.*}} @_ZN5test71XIiEC1IdEEPT_PNS_5int_cIXplL_ZNS_4metaIiE5valueEEsr4metaIS3_EE5valueEE4typeE( |
83 | template X<int>::X(double*, float*); |
84 | } |
85 | |
86 | namespace test8 { |
87 | template<typename T> |
88 | struct meta { |
89 | struct type { |
90 | static const unsigned value = sizeof(T); |
91 | }; |
92 | }; |
93 | |
94 | template<unsigned> struct int_c { |
95 | typedef float type; |
96 | }; |
97 | |
98 | template<typename T> |
99 | void f(int_c<meta<T>::type::value>) { } |
100 | |
101 | // CHECK-LABEL: define weak_odr {{.*}}void @_ZN5test81fIiEEvNS_5int_cIXsr4metaIT_E4typeE5valueEEE( |
102 | template void f<int>(int_c<sizeof(int)>); |
103 | } |
104 | |
105 | namespace test9 { |
106 | template<typename T> |
107 | struct supermeta { |
108 | template<typename U> |
109 | struct apply { |
110 | typedef T U::*type; |
111 | }; |
112 | }; |
113 | |
114 | struct X { }; |
115 | |
116 | template<typename T, typename U> |
117 | typename supermeta<T>::template apply<U>::type f(); |
118 | |
119 | void test_f() { |
120 | // CHECK: @_ZN5test91fIiNS_1XEEENS_9supermetaIT_E5applyIT0_E4typeEv() |
121 | // Note: GCC incorrectly mangles this as |
122 | // _ZN5test91fIiNS_1XEEENS_9supermetaIT_E5apply4typeEv, while EDG |
123 | // gets it right. |
124 | f<int, X>(); |
125 | } |
126 | } |
127 | |
128 | namespace test10 { |
129 | template<typename T> |
130 | struct X { |
131 | template<typename U> |
132 | struct definition { |
133 | }; |
134 | }; |
135 | |
136 | // CHECK: _ZN6test101fIidEENS_1XIT_E10definitionIT0_EES2_S5_ |
137 | template<typename T, typename U> |
138 | typename X<T>::template definition<U> f(T, U) { } |
139 | |
140 | void g(int i, double d) { |
141 | f(i, d); |
142 | } |
143 | } |
144 | |
145 | // Report from cxx-abi-dev, 2012.01.04. |
146 | namespace test11 { |
147 | int cmp(char a, char b); |
148 | template <typename T, int (*cmp)(T, T)> struct A {}; |
149 | template <typename T> void f(A<T,cmp> &) {} |
150 | template void f<char>(A<char,cmp> &); |
151 | // CHECK: @_ZN6test111fIcEEvRNS_1AIT_L_ZNS_3cmpEccEEE( |
152 | } |
153 | |
154 | namespace test12 { |
155 | // Make sure we can mangle non-type template args with internal linkage. |
156 | static int f() {} |
157 | const int n = 10; |
158 | template<typename T, T v> void test() {} |
159 | void use() { |
160 | // CHECK-LABEL: define internal {{.*}}void @_ZN6test124testIFivEXadL_ZNS_L1fEvEEEEvv( |
161 | test<int(), &f>(); |
162 | // CHECK-LABEL: define internal {{.*}}void @_ZN6test124testIRFivEL_ZNS_L1fEvEEEvv( |
163 | test<int(&)(), f>(); |
164 | // CHECK-LABEL: define internal {{.*}}void @_ZN6test124testIPKiXadL_ZNS_L1nEEEEEvv( |
165 | test<const int*, &n>(); |
166 | // CHECK-LABEL: define internal {{.*}}void @_ZN6test124testIRKiL_ZNS_L1nEEEEvv( |
167 | test<const int&, n>(); |
168 | } |
169 | } |
170 | |
171 | // rdar://problem/12072531 |
172 | // Test the boundary condition of minimal signed integers. |
173 | namespace test13 { |
174 | template <char c> char returnChar() { return c; } |
175 | template char returnChar<-128>(); |
176 | // CHECK: @_ZN6test1310returnCharILcn128EEEcv() |
177 | |
178 | template <short s> short returnShort() { return s; } |
179 | template short returnShort<-32768>(); |
180 | // CHECK: @_ZN6test1311returnShortILsn32768EEEsv() |
181 | } |
182 | |
183 | namespace test14 { |
184 | template <typename> inline int inl(bool b) { |
185 | if (b) { |
186 | static struct { |
187 | int field; |
188 | } a; |
189 | // CHECK: @_ZZN6test143inlIvEEibE1a |
190 | |
191 | return a.field; |
192 | } else { |
193 | static struct { |
194 | int field; |
195 | } a; |
196 | // CHECK: @_ZZN6test143inlIvEEibE1a_0 |
197 | |
198 | return a.field; |
199 | } |
200 | } |
201 | |
202 | int call(bool b) { return inl<void>(b); } |
203 | } |
204 | |
205 | namespace std { |
206 | template <class _Tp, _Tp...> struct integer_sequence {}; |
207 | } |
208 | |
209 | namespace test15 { |
210 | template <int N> |
211 | __make_integer_seq<std::integer_sequence, int, N> make() {} |
212 | template __make_integer_seq<std::integer_sequence, int, 5> make<5>(); |
213 | // CHECK: define weak_odr {{.*}} @_ZN6test154makeILi5EEE18__make_integer_seqISt16integer_sequenceiXT_EEv( |
214 | } |
215 | |