blob: db154f6076b4b0ec1b7ed9caa11150b3caf84051 [file] [log] [blame]
Douglas Gregorc8ab2562009-05-31 09:31:02 +00001// RUN: clang-cc -fsyntax-only -verify %s
2template<typename T>
3struct is_pointer {
4 static const bool value = false;
5};
6
7template<typename T>
8struct is_pointer<T*> {
9 static const bool value = true;
10};
11
12template<typename T>
13struct is_pointer<const T*> {
14 static const bool value = true;
15};
16
17int array0[is_pointer<int>::value? -1 : 1];
18int array1[is_pointer<int*>::value? 1 : -1];
19int array2[is_pointer<const int*>::value? 1 : -1]; // expected-error{{partial ordering}} \
20// expected-error{{negative}}
Douglas Gregor0b9247f2009-06-04 00:03:07 +000021
Douglas Gregord560d502009-06-04 00:21:18 +000022template<typename T>
23struct is_lvalue_reference {
24 static const bool value = false;
25};
26
27template<typename T>
28struct is_lvalue_reference<T&> {
29 static const bool value = true;
30};
31
32int lvalue_ref0[is_lvalue_reference<int>::value? -1 : 1];
33int lvalue_ref1[is_lvalue_reference<const int&>::value? 1 : -1];
34
Douglas Gregor9e9fae42009-07-22 20:02:25 +000035template<typename T>
36struct is_const {
37 static const bool value = false;
38};
39
40template<typename T>
41struct is_const<const T> {
42 static const bool value = true;
43};
44
45int is_const0[is_const<int>::value? -1 : 1];
46int is_const1[is_const<const int>::value? 1 : -1];
47int is_const2[is_const<const volatile int>::value? 1 : -1];
Douglas Gregor1f618a02009-07-22 20:07:21 +000048int is_const3[is_const<const int [3]>::value? 1 : -1];
49int is_const4[is_const<const volatile int[3]>::value? 1 : -1];
50int is_const4[is_const<volatile int[3]>::value? -1 : 1];
Douglas Gregor9e9fae42009-07-22 20:02:25 +000051
52template<typename T>
53struct is_volatile {
54 static const bool value = false;
55};
56
57template<typename T>
58struct is_volatile<volatile T> {
59 static const bool value = true;
60};
61
62int is_volatile0[is_volatile<int>::value? -1 : 1];
63int is_volatile1[is_volatile<volatile int>::value? 1 : -1];
64int is_volatile2[is_volatile<const volatile int>::value? 1 : -1];
65int is_volatile3[is_volatile<volatile char[3]>::value? 1 : -1];
66
Douglas Gregor0b9247f2009-06-04 00:03:07 +000067template<typename T, typename U>
68struct is_same {
69 static const bool value = false;
70};
71
72template<typename T>
73struct is_same<T, T> {
74 static const bool value = true;
75};
76
77typedef int INT;
78typedef INT* int_ptr;
79
80int is_same0[is_same<int, int>::value? 1 : -1];
81int is_same1[is_same<int, INT>::value? 1 : -1];
82int is_same2[is_same<const int, int>::value? -1 : 1];
83int is_same3[is_same<int_ptr, int>::value? -1 : 1];
Anders Carlsson4d6fb502009-06-04 04:11:30 +000084
85template<typename T>
Douglas Gregor199d9912009-06-05 00:53:49 +000086struct remove_reference {
87 typedef T type;
88};
89
90template<typename T>
91struct remove_reference<T&> {
92 typedef T type;
93};
94
95int remove_ref0[is_same<remove_reference<int>::type, int>::value? 1 : -1];
96int remove_ref1[is_same<remove_reference<int&>::type, int>::value? 1 : -1];
97
98template<typename T>
Anders Carlsson4d6fb502009-06-04 04:11:30 +000099struct is_incomplete_array {
100 static const bool value = false;
101};
102
103template<typename T>
104struct is_incomplete_array<T[]> {
105 static const bool value = true;
106};
107
108int incomplete_array0[is_incomplete_array<int>::value ? -1 : 1];
109int incomplete_array1[is_incomplete_array<int[1]>::value ? -1 : 1];
110int incomplete_array2[is_incomplete_array<bool[]>::value ? 1 : -1];
111int incomplete_array3[is_incomplete_array<int[]>::value ? 1 : -1];
112
113template<typename T>
114struct is_array_with_4_elements {
115 static const bool value = false;
116};
117
118template<typename T>
119struct is_array_with_4_elements<T[4]> {
120 static const bool value = true;
121};
122
123int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1];
124int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1];
125int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1];
126int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1];
Douglas Gregor199d9912009-06-05 00:53:49 +0000127
128template<typename T>
129struct get_array_size;
130
131template<typename T, unsigned N>
132struct get_array_size<T[N]> {
133 static const unsigned value = N;
134};
135
136int array_size0[get_array_size<int[12]>::value == 12? 1 : -1];
Anders Carlssona27fad52009-06-08 15:19:08 +0000137
138template<typename T>
139struct is_unary_function {
140 static const bool value = false;
141};
142
143template<typename T, typename U>
144struct is_unary_function<T (*)(U)> {
145 static const bool value = true;
146};
147
148int is_unary_function0[is_unary_function<int>::value ? -1 : 1];
149int is_unary_function1[is_unary_function<int (*)()>::value ? -1 : 1];
150int is_unary_function2[is_unary_function<int (*)(int, bool)>::value ? -1 : 1];
151int is_unary_function3[is_unary_function<int (*)(bool)>::value ? 1 : -1];
152int is_unary_function4[is_unary_function<int (*)(int)>::value ? 1 : -1];
153
154template<typename T>
155struct is_unary_function_with_same_return_type_as_argument_type {
156 static const bool value = false;
157};
158
159template<typename T>
160struct is_unary_function_with_same_return_type_as_argument_type<T (*)(T)> {
161 static const bool value = true;
162};
163
164int is_unary_function5[is_unary_function_with_same_return_type_as_argument_type<int>::value ? -1 : 1];
165int is_unary_function6[is_unary_function_with_same_return_type_as_argument_type<int (*)()>::value ? -1 : 1];
166int is_unary_function7[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, bool)>::value ? -1 : 1];
167int is_unary_function8[is_unary_function_with_same_return_type_as_argument_type<int (*)(bool)>::value ? -1 : 1];
168int is_unary_function9[is_unary_function_with_same_return_type_as_argument_type<int (*)(int)>::value ? 1 : -1];
Anders Carlsson994b6cb2009-06-08 19:22:23 +0000169int is_unary_function10[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, ...)>::value ? -1 : 1];
170int is_unary_function11[is_unary_function_with_same_return_type_as_argument_type<int (* const)(int)>::value ? -1 : 1];
Douglas Gregor1fe067a2009-06-08 16:04:08 +0000171
172template<typename T>
173struct is_binary_function {
174 static const bool value = false;
175};
176
177template<typename R, typename T1, typename T2>
178struct is_binary_function<R(T1, T2)> {
179 static const bool value = true;
180};
181
182int is_binary_function0[is_binary_function<int(float, double)>::value? 1 : -1];
Douglas Gregor949bf692009-06-09 22:17:39 +0000183
184template<typename T>
185struct is_member_pointer {
186 static const bool value = false;
187};
188
189template<typename T, typename Class>
190struct is_member_pointer<T Class::*> {
191 static const bool value = true;
192};
Douglas Gregor637a4092009-06-10 23:47:09 +0000193
194struct X { };
195
196int is_member_pointer0[is_member_pointer<int X::*>::value? 1 : -1];
197int is_member_pointer1[is_member_pointer<const int X::*>::value? 1 : -1];
198int is_member_pointer2[is_member_pointer<int (X::*)()>::value? 1 : -1];
199int is_member_pointer3[is_member_pointer<int (X::*)(int) const>::value? 1 : -1];
200int is_member_pointer4[is_member_pointer<int (X::**)(int) const>::value? -1 : 1];
201int is_member_pointer5[is_member_pointer<int>::value? -1 : 1];
202
203template<typename T>
204struct is_member_function_pointer {
205 static const bool value = false;
206};
207
208template<typename T, typename Class>
209struct is_member_function_pointer<T (Class::*)()> {
210 static const bool value = true;
211};
212
213template<typename T, typename Class>
214struct is_member_function_pointer<T (Class::*)() const> {
215 static const bool value = true;
216};
217
218template<typename T, typename Class>
219struct is_member_function_pointer<T (Class::*)() volatile> {
220 static const bool value = true;
221};
222
223template<typename T, typename Class>
224struct is_member_function_pointer<T (Class::*)() const volatile> {
225 static const bool value = true;
226};
227
228template<typename T, typename Class, typename A1>
229struct is_member_function_pointer<T (Class::*)(A1)> {
230 static const bool value = true;
231};
232
233template<typename T, typename Class, typename A1>
234struct is_member_function_pointer<T (Class::*)(A1) const> {
235 static const bool value = true;
236};
237
238template<typename T, typename Class, typename A1>
239struct is_member_function_pointer<T (Class::*)(A1) volatile> {
240 static const bool value = true;
241};
242
243template<typename T, typename Class, typename A1>
244struct is_member_function_pointer<T (Class::*)(A1) const volatile> {
245 static const bool value = true;
246};
247
248int is_member_function_pointer0[
249 is_member_function_pointer<int X::*>::value? -1 : 1];
250int is_member_function_pointer1[
251 is_member_function_pointer<int (X::*)()>::value? 1 : -1];
252int is_member_function_pointer2[
253 is_member_function_pointer<X (X::*)(X&)>::value? 1 : -1];
254int is_member_function_pointer3[
255 is_member_function_pointer<int (X::*)() const>::value? 1 : -1];
256int is_member_function_pointer4[
257 is_member_function_pointer<int (X::*)(float) const>::value? 1 : -1];
258
Douglas Gregor02cbbd22009-06-11 18:10:32 +0000259// Test substitution of non-dependent arguments back into the template
260// argument list of the class template partial specialization.
Douglas Gregor637a4092009-06-10 23:47:09 +0000261template<typename T, typename ValueType = T>
262struct is_nested_value_type_identity {
263 static const bool value = false;
264};
265
266template<typename T>
267struct is_nested_value_type_identity<T, typename T::value_type> {
268 static const bool value = true;
269};
270
271template<typename T>
272struct HasValueType {
273 typedef T value_type;
274};
275
276struct HasIdentityValueType {
277 typedef HasIdentityValueType value_type;
278};
279
280struct NoValueType { };
281
Douglas Gregor02cbbd22009-06-11 18:10:32 +0000282int is_nested_value_type_identity0[
283 is_nested_value_type_identity<HasValueType<int> >::value? -1 : 1];
Douglas Gregor637a4092009-06-10 23:47:09 +0000284int is_nested_value_type_identity1[
285 is_nested_value_type_identity<HasIdentityValueType>::value? 1 : -1];
Douglas Gregor5e9f35c2009-06-14 07:33:30 +0000286int is_nested_value_type_identity2[
287 is_nested_value_type_identity<NoValueType>::value? -1 : 1];
Douglas Gregor02cbbd22009-06-11 18:10:32 +0000288
Douglas Gregor16df8502009-06-12 22:21:45 +0000289
290// C++ [temp.class.spec]p4:
291template<class T1, class T2, int I> class A { }; //#1
292template<class T, int I> class A<T, T*, I> { }; //#2
293template<class T1, class T2, int I> class A<T1*, T2, I> { }; //#3
294template<class T> class A<int, T*, 5> { }; //#4
295template<class T1, class T2, int I> class A<T1, T2*, I> { }; //#5