blob: da3435071792af70685af1491388d70d3cd1ccd1 [file] [log] [blame]
Douglas Gregor2373c592009-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 Gregor55ca8f62009-06-04 00:03:07 +000021
Douglas Gregor5cdac0a2009-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 Gregor60454822009-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];
48
49template<typename T>
50struct is_volatile {
51 static const bool value = false;
52};
53
54template<typename T>
55struct is_volatile<volatile T> {
56 static const bool value = true;
57};
58
59int is_volatile0[is_volatile<int>::value? -1 : 1];
60int is_volatile1[is_volatile<volatile int>::value? 1 : -1];
61int is_volatile2[is_volatile<const volatile int>::value? 1 : -1];
62int is_volatile3[is_volatile<volatile char[3]>::value? 1 : -1];
63
Douglas Gregor55ca8f62009-06-04 00:03:07 +000064template<typename T, typename U>
65struct is_same {
66 static const bool value = false;
67};
68
69template<typename T>
70struct is_same<T, T> {
71 static const bool value = true;
72};
73
74typedef int INT;
75typedef INT* int_ptr;
76
77int is_same0[is_same<int, int>::value? 1 : -1];
78int is_same1[is_same<int, INT>::value? 1 : -1];
79int is_same2[is_same<const int, int>::value? -1 : 1];
80int is_same3[is_same<int_ptr, int>::value? -1 : 1];
Anders Carlsson35533d12009-06-04 04:11:30 +000081
82template<typename T>
Douglas Gregorb7ae10f2009-06-05 00:53:49 +000083struct remove_reference {
84 typedef T type;
85};
86
87template<typename T>
88struct remove_reference<T&> {
89 typedef T type;
90};
91
92int remove_ref0[is_same<remove_reference<int>::type, int>::value? 1 : -1];
93int remove_ref1[is_same<remove_reference<int&>::type, int>::value? 1 : -1];
94
95template<typename T>
Anders Carlsson35533d12009-06-04 04:11:30 +000096struct is_incomplete_array {
97 static const bool value = false;
98};
99
100template<typename T>
101struct is_incomplete_array<T[]> {
102 static const bool value = true;
103};
104
105int incomplete_array0[is_incomplete_array<int>::value ? -1 : 1];
106int incomplete_array1[is_incomplete_array<int[1]>::value ? -1 : 1];
107int incomplete_array2[is_incomplete_array<bool[]>::value ? 1 : -1];
108int incomplete_array3[is_incomplete_array<int[]>::value ? 1 : -1];
109
110template<typename T>
111struct is_array_with_4_elements {
112 static const bool value = false;
113};
114
115template<typename T>
116struct is_array_with_4_elements<T[4]> {
117 static const bool value = true;
118};
119
120int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1];
121int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1];
122int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1];
123int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1];
Douglas Gregorb7ae10f2009-06-05 00:53:49 +0000124
125template<typename T>
126struct get_array_size;
127
128template<typename T, unsigned N>
129struct get_array_size<T[N]> {
130 static const unsigned value = N;
131};
132
133int array_size0[get_array_size<int[12]>::value == 12? 1 : -1];
Anders Carlsson2128ec72009-06-08 15:19:08 +0000134
135template<typename T>
136struct is_unary_function {
137 static const bool value = false;
138};
139
140template<typename T, typename U>
141struct is_unary_function<T (*)(U)> {
142 static const bool value = true;
143};
144
145int is_unary_function0[is_unary_function<int>::value ? -1 : 1];
146int is_unary_function1[is_unary_function<int (*)()>::value ? -1 : 1];
147int is_unary_function2[is_unary_function<int (*)(int, bool)>::value ? -1 : 1];
148int is_unary_function3[is_unary_function<int (*)(bool)>::value ? 1 : -1];
149int is_unary_function4[is_unary_function<int (*)(int)>::value ? 1 : -1];
150
151template<typename T>
152struct is_unary_function_with_same_return_type_as_argument_type {
153 static const bool value = false;
154};
155
156template<typename T>
157struct is_unary_function_with_same_return_type_as_argument_type<T (*)(T)> {
158 static const bool value = true;
159};
160
161int is_unary_function5[is_unary_function_with_same_return_type_as_argument_type<int>::value ? -1 : 1];
162int is_unary_function6[is_unary_function_with_same_return_type_as_argument_type<int (*)()>::value ? -1 : 1];
163int is_unary_function7[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, bool)>::value ? -1 : 1];
164int is_unary_function8[is_unary_function_with_same_return_type_as_argument_type<int (*)(bool)>::value ? -1 : 1];
165int is_unary_function9[is_unary_function_with_same_return_type_as_argument_type<int (*)(int)>::value ? 1 : -1];
Anders Carlsson096e6ee2009-06-08 19:22:23 +0000166int is_unary_function10[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, ...)>::value ? -1 : 1];
167int is_unary_function11[is_unary_function_with_same_return_type_as_argument_type<int (* const)(int)>::value ? -1 : 1];
Douglas Gregor6f998fc2009-06-08 16:04:08 +0000168
169template<typename T>
170struct is_binary_function {
171 static const bool value = false;
172};
173
174template<typename R, typename T1, typename T2>
175struct is_binary_function<R(T1, T2)> {
176 static const bool value = true;
177};
178
179int is_binary_function0[is_binary_function<int(float, double)>::value? 1 : -1];
Douglas Gregor0bdc1f52009-06-09 22:17:39 +0000180
181template<typename T>
182struct is_member_pointer {
183 static const bool value = false;
184};
185
186template<typename T, typename Class>
187struct is_member_pointer<T Class::*> {
188 static const bool value = true;
189};
Douglas Gregor637d9982009-06-10 23:47:09 +0000190
191struct X { };
192
193int is_member_pointer0[is_member_pointer<int X::*>::value? 1 : -1];
194int is_member_pointer1[is_member_pointer<const int X::*>::value? 1 : -1];
195int is_member_pointer2[is_member_pointer<int (X::*)()>::value? 1 : -1];
196int is_member_pointer3[is_member_pointer<int (X::*)(int) const>::value? 1 : -1];
197int is_member_pointer4[is_member_pointer<int (X::**)(int) const>::value? -1 : 1];
198int is_member_pointer5[is_member_pointer<int>::value? -1 : 1];
199
200template<typename T>
201struct is_member_function_pointer {
202 static const bool value = false;
203};
204
205template<typename T, typename Class>
206struct is_member_function_pointer<T (Class::*)()> {
207 static const bool value = true;
208};
209
210template<typename T, typename Class>
211struct is_member_function_pointer<T (Class::*)() const> {
212 static const bool value = true;
213};
214
215template<typename T, typename Class>
216struct is_member_function_pointer<T (Class::*)() volatile> {
217 static const bool value = true;
218};
219
220template<typename T, typename Class>
221struct is_member_function_pointer<T (Class::*)() const volatile> {
222 static const bool value = true;
223};
224
225template<typename T, typename Class, typename A1>
226struct is_member_function_pointer<T (Class::*)(A1)> {
227 static const bool value = true;
228};
229
230template<typename T, typename Class, typename A1>
231struct is_member_function_pointer<T (Class::*)(A1) const> {
232 static const bool value = true;
233};
234
235template<typename T, typename Class, typename A1>
236struct is_member_function_pointer<T (Class::*)(A1) volatile> {
237 static const bool value = true;
238};
239
240template<typename T, typename Class, typename A1>
241struct is_member_function_pointer<T (Class::*)(A1) const volatile> {
242 static const bool value = true;
243};
244
245int is_member_function_pointer0[
246 is_member_function_pointer<int X::*>::value? -1 : 1];
247int is_member_function_pointer1[
248 is_member_function_pointer<int (X::*)()>::value? 1 : -1];
249int is_member_function_pointer2[
250 is_member_function_pointer<X (X::*)(X&)>::value? 1 : -1];
251int is_member_function_pointer3[
252 is_member_function_pointer<int (X::*)() const>::value? 1 : -1];
253int is_member_function_pointer4[
254 is_member_function_pointer<int (X::*)(float) const>::value? 1 : -1];
255
Douglas Gregor74eba0b2009-06-11 18:10:32 +0000256// Test substitution of non-dependent arguments back into the template
257// argument list of the class template partial specialization.
Douglas Gregor637d9982009-06-10 23:47:09 +0000258template<typename T, typename ValueType = T>
259struct is_nested_value_type_identity {
260 static const bool value = false;
261};
262
263template<typename T>
264struct is_nested_value_type_identity<T, typename T::value_type> {
265 static const bool value = true;
266};
267
268template<typename T>
269struct HasValueType {
270 typedef T value_type;
271};
272
273struct HasIdentityValueType {
274 typedef HasIdentityValueType value_type;
275};
276
277struct NoValueType { };
278
Douglas Gregor74eba0b2009-06-11 18:10:32 +0000279int is_nested_value_type_identity0[
280 is_nested_value_type_identity<HasValueType<int> >::value? -1 : 1];
Douglas Gregor637d9982009-06-10 23:47:09 +0000281int is_nested_value_type_identity1[
282 is_nested_value_type_identity<HasIdentityValueType>::value? 1 : -1];
Douglas Gregor33834512009-06-14 07:33:30 +0000283int is_nested_value_type_identity2[
284 is_nested_value_type_identity<NoValueType>::value? -1 : 1];
Douglas Gregor74eba0b2009-06-11 18:10:32 +0000285
Douglas Gregor30b01972009-06-12 22:21:45 +0000286
287// C++ [temp.class.spec]p4:
288template<class T1, class T2, int I> class A { }; //#1
289template<class T, int I> class A<T, T*, I> { }; //#2
290template<class T1, class T2, int I> class A<T1*, T2, I> { }; //#3
291template<class T> class A<int, T*, 5> { }; //#4
292template<class T1, class T2, int I> class A<T1, T2*, I> { }; //#5