• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 template<typename T>
3 struct is_pointer {
4   static const bool value = false;
5 };
6 
7 template<typename T>
8 struct is_pointer<T*> {
9   static const bool value = true;
10 };
11 
12 template<typename T>
13 struct is_pointer<const T*> {
14   static const bool value = true;
15 };
16 
17 int array0[is_pointer<int>::value? -1 : 1];
18 int array1[is_pointer<int*>::value? 1 : -1];
19 int array2[is_pointer<const int*>::value? 1 : -1];
20 
21 template<typename T>
22 struct is_lvalue_reference {
23   static const bool value = false;
24 };
25 
26 template<typename T>
27 struct is_lvalue_reference<T&> {
28   static const bool value = true;
29 };
30 
31 int lvalue_ref0[is_lvalue_reference<int>::value? -1 : 1];
32 int lvalue_ref1[is_lvalue_reference<const int&>::value? 1 : -1];
33 
34 template<typename T>
35 struct is_const {
36   static const bool value = false;
37 };
38 
39 template<typename T>
40 struct is_const<const T> {
41   static const bool value = true;
42 };
43 
44 int is_const0[is_const<int>::value? -1 : 1];
45 int is_const1[is_const<const int>::value? 1 : -1];
46 int is_const2[is_const<const volatile int>::value? 1 : -1];
47 int is_const3[is_const<const int [3]>::value? 1 : -1];
48 int is_const4[is_const<const volatile int[3]>::value? 1 : -1];
49 int is_const5[is_const<volatile int[3]>::value? -1 : 1];
50 
51 template<typename T>
52 struct is_volatile {
53   static const bool value = false;
54 };
55 
56 template<typename T>
57 struct is_volatile<volatile T> {
58   static const bool value = true;
59 };
60 
61 int is_volatile0[is_volatile<int>::value? -1 : 1];
62 int is_volatile1[is_volatile<volatile int>::value? 1 : -1];
63 int is_volatile2[is_volatile<const volatile int>::value? 1 : -1];
64 int is_volatile3[is_volatile<volatile char[3]>::value? 1 : -1];
65 
66 template<typename T, typename U>
67 struct is_same {
68   static const bool value = false;
69 };
70 
71 template<typename T>
72 struct is_same<T, T> {
73   static const bool value = true;
74 };
75 
76 typedef int INT;
77 typedef INT* int_ptr;
78 
79 int is_same0[is_same<int, int>::value? 1 : -1];
80 int is_same1[is_same<int, INT>::value? 1 : -1];
81 int is_same2[is_same<const int, int>::value? -1 : 1];
82 int is_same3[is_same<int_ptr, int>::value? -1 : 1];
83 
84 template<typename T>
85 struct remove_reference {
86   typedef T type;
87 };
88 
89 template<typename T>
90 struct remove_reference<T&> {
91   typedef T type;
92 };
93 
94 int remove_ref0[is_same<remove_reference<int>::type, int>::value? 1 : -1];
95 int remove_ref1[is_same<remove_reference<int&>::type, int>::value? 1 : -1];
96 
97 template<typename T>
98 struct remove_const {
99   typedef T type;
100 };
101 
102 template<typename T>
103 struct remove_const<const T> {
104   typedef T type;
105 };
106 
107 int remove_const0[is_same<remove_const<const int>::type, int>::value? 1 : -1];
108 int remove_const1[is_same<remove_const<const int[3]>::type, int[3]>::value? 1 : -1];
109 
110 template<typename T>
111 struct is_incomplete_array {
112   static const bool value = false;
113 };
114 
115 template<typename T>
116 struct is_incomplete_array<T[]> {
117   static const bool value = true;
118 };
119 
120 int incomplete_array0[is_incomplete_array<int>::value ? -1 : 1];
121 int incomplete_array1[is_incomplete_array<int[1]>::value ? -1 : 1];
122 int incomplete_array2[is_incomplete_array<bool[]>::value ? 1 : -1];
123 int incomplete_array3[is_incomplete_array<int[]>::value ? 1 : -1];
124 
125 template<typename T>
126 struct is_array_with_4_elements {
127   static const bool value = false;
128 };
129 
130 template<typename T>
131 struct is_array_with_4_elements<T[4]> {
132   static const bool value = true;
133 };
134 
135 int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1];
136 int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1];
137 int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1];
138 int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1];
139 
140 template<typename T>
141 struct get_array_size;
142 
143 template<typename T, unsigned N>
144 struct get_array_size<T[N]> {
145   static const unsigned value = N;
146 };
147 
148 int array_size0[get_array_size<int[12]>::value == 12? 1 : -1];
149 
150 template<typename T>
151 struct remove_extent {
152   typedef T type;
153 };
154 
155 template<typename T>
156 struct remove_extent<T[]> {
157   typedef T type;
158 };
159 
160 template<typename T, unsigned N>
161 struct remove_extent<T[N]> {
162   typedef T type;
163 };
164 
165 int remove_extent0[is_same<remove_extent<int[][5]>::type, int[5]>::value? 1 : -1];
166 int remove_extent1[is_same<remove_extent<const int[][5]>::type, const int[5]>::value? 1 : -1];
167 
168 template<typename T>
169 struct is_unary_function {
170   static const bool value = false;
171 };
172 
173 template<typename T, typename U>
174 struct is_unary_function<T (*)(U)> {
175   static const bool value = true;
176 };
177 
178 int is_unary_function0[is_unary_function<int>::value ? -1 : 1];
179 int is_unary_function1[is_unary_function<int (*)()>::value ? -1 : 1];
180 int is_unary_function2[is_unary_function<int (*)(int, bool)>::value ? -1 : 1];
181 int is_unary_function3[is_unary_function<int (*)(bool)>::value ? 1 : -1];
182 int is_unary_function4[is_unary_function<int (*)(int)>::value ? 1 : -1];
183 
184 template<typename T>
185 struct is_unary_function_with_same_return_type_as_argument_type {
186   static const bool value = false;
187 };
188 
189 template<typename T>
190 struct is_unary_function_with_same_return_type_as_argument_type<T (*)(T)> {
191   static const bool value = true;
192 };
193 
194 int is_unary_function5[is_unary_function_with_same_return_type_as_argument_type<int>::value ? -1 : 1];
195 int is_unary_function6[is_unary_function_with_same_return_type_as_argument_type<int (*)()>::value ? -1 : 1];
196 int is_unary_function7[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, bool)>::value ? -1 : 1];
197 int is_unary_function8[is_unary_function_with_same_return_type_as_argument_type<int (*)(bool)>::value ? -1 : 1];
198 int is_unary_function9[is_unary_function_with_same_return_type_as_argument_type<int (*)(int)>::value ? 1 : -1];
199 int is_unary_function10[is_unary_function_with_same_return_type_as_argument_type<int (*)(int, ...)>::value ? -1 : 1];
200 int is_unary_function11[is_unary_function_with_same_return_type_as_argument_type<int (* const)(int)>::value ? -1 : 1];
201 
202 template<typename T>
203 struct is_binary_function {
204   static const bool value = false;
205 };
206 
207 template<typename R, typename T1, typename T2>
208 struct is_binary_function<R(T1, T2)> {
209   static const bool value = true;
210 };
211 
212 int is_binary_function0[is_binary_function<int(float, double)>::value? 1 : -1];
213 
214 template<typename T>
215 struct is_member_pointer {
216   static const bool value = false;
217 };
218 
219 template<typename T, typename Class>
220 struct is_member_pointer<T Class::*> {
221   static const bool value = true;
222 };
223 
224 struct X { };
225 
226 int is_member_pointer0[is_member_pointer<int X::*>::value? 1 : -1];
227 int is_member_pointer1[is_member_pointer<const int X::*>::value? 1 : -1];
228 int is_member_pointer2[is_member_pointer<int (X::*)()>::value? 1 : -1];
229 int is_member_pointer3[is_member_pointer<int (X::*)(int) const>::value? 1 : -1];
230 int is_member_pointer4[is_member_pointer<int (X::**)(int) const>::value? -1 : 1];
231 int is_member_pointer5[is_member_pointer<int>::value? -1 : 1];
232 
233 template<typename T>
234 struct is_member_function_pointer {
235   static const bool value = false;
236 };
237 
238 template<typename T, typename Class>
239 struct is_member_function_pointer<T (Class::*)()> {
240   static const bool value = true;
241 };
242 
243 template<typename T, typename Class>
244 struct is_member_function_pointer<T (Class::*)() const> {
245   static const bool value = true;
246 };
247 
248 template<typename T, typename Class>
249 struct is_member_function_pointer<T (Class::*)() volatile> {
250   static const bool value = true;
251 };
252 
253 template<typename T, typename Class>
254 struct is_member_function_pointer<T (Class::*)() const volatile> {
255   static const bool value = true;
256 };
257 
258 template<typename T, typename Class, typename A1>
259 struct is_member_function_pointer<T (Class::*)(A1)> {
260   static const bool value = true;
261 };
262 
263 template<typename T, typename Class, typename A1>
264 struct is_member_function_pointer<T (Class::*)(A1) const> {
265   static const bool value = true;
266 };
267 
268 template<typename T, typename Class, typename A1>
269 struct is_member_function_pointer<T (Class::*)(A1) volatile> {
270   static const bool value = true;
271 };
272 
273 template<typename T, typename Class, typename A1>
274 struct is_member_function_pointer<T (Class::*)(A1) const volatile> {
275   static const bool value = true;
276 };
277 
278 int is_member_function_pointer0[
279                           is_member_function_pointer<int X::*>::value? -1 : 1];
280 int is_member_function_pointer1[
281                       is_member_function_pointer<int (X::*)()>::value? 1 : -1];
282 int is_member_function_pointer2[
283                       is_member_function_pointer<X (X::*)(X&)>::value? 1 : -1];
284 int is_member_function_pointer3[
285            is_member_function_pointer<int (X::*)() const>::value? 1 : -1];
286 int is_member_function_pointer4[
287            is_member_function_pointer<int (X::*)(float) const>::value? 1 : -1];
288 
289 // Test substitution of non-dependent arguments back into the template
290 // argument list of the class template partial specialization.
291 template<typename T, typename ValueType = T>
292 struct is_nested_value_type_identity {
293   static const bool value = false;
294 };
295 
296 template<typename T>
297 struct is_nested_value_type_identity<T, typename T::value_type> {
298   static const bool value = true;
299 };
300 
301 template<typename T>
302 struct HasValueType {
303   typedef T value_type;
304 };
305 
306 struct HasIdentityValueType {
307   typedef HasIdentityValueType value_type;
308 };
309 
310 struct NoValueType { };
311 
312 int is_nested_value_type_identity0[
313             is_nested_value_type_identity<HasValueType<int> >::value? -1 : 1];
314 int is_nested_value_type_identity1[
315           is_nested_value_type_identity<HasIdentityValueType>::value? 1 : -1];
316 int is_nested_value_type_identity2[
317                    is_nested_value_type_identity<NoValueType>::value? -1 : 1];
318 
319 
320 // C++ [temp.class.spec]p4:
321 template<class T1, class T2, int I> class A { }; //#1
322 template<class T, int I> class A<T, T*, I> { }; //#2
323 template<class T1, class T2, int I> class A<T1*, T2, I> { }; //#3
324 template<class T> class A<int, T*, 5> { }; //#4
325 template<class T1, class T2, int I> class A<T1, T2*, I> { }; //#5
326 
327 // Redefinition of class template partial specializations
328 template<typename T, T N, typename U> class A0;
329 
330 template<typename T, T N> class A0<T, N, int> { }; // expected-note{{here}}
331 template<typename T, T N> class A0<T, N, int>;
332 template<typename T, T N> class A0<T, N, int> { }; // expected-error{{redef}}
333 
334 namespace PR6025 {
335   template< int N > struct A;
336 
337   namespace N
338   {
339     template< typename F >
340     struct B;
341   }
342 
343   template< typename Protect, typename Second >
344   struct C;
345 
346   template <class T>
347   struct C< T, A< N::B<T>::value > >
348   {
349   };
350 }
351 
352 namespace PR6181 {
353   template <class T>
354   class a;
355 
356   class s;
357 
358   template <class U>
359   class a<s> // expected-error{{partial specialization of 'a' does not use any of its template parameters}}
360   {
361   };
362 
363 }
364