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