1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11 11 12 // GCC returns true for __is_trivially_constructible(void, int) 13 // See gcc.gnu.org/PR80682 14 // NOTE: This has been fixed in trunk and will be backported soon. 15 // XFAIL: gcc-7, gcc-6, gcc-5, gcc-4 16 17 // <experimental/type_traits> 18 19 #include <experimental/type_traits> 20 21 namespace ex = std::experimental; 22 23 struct non_literal_type { non_literal_type() {} }; 24 struct empty_type {}; 25 26 struct polymorphic_type 27 { 28 virtual void foo() {} 29 }; 30 31 struct abstract_type 32 { 33 virtual void foo() = 0; 34 }; 35 36 struct final_type final {}; 37 38 struct virtual_dtor_type 39 { 40 virtual ~virtual_dtor_type() {} 41 }; 42 43 void type_properties_test() 44 { 45 { 46 typedef const int T; 47 static_assert(ex::is_const_v<T>, ""); 48 static_assert(std::is_same<decltype(ex::is_const_v<T>), const bool>::value, ""); 49 static_assert(ex::is_const_v<T> == std::is_const<T>::value, ""); 50 } 51 { 52 typedef int T; 53 static_assert(!ex::is_const_v<T>, ""); 54 static_assert(ex::is_const_v<T> == std::is_const<T>::value, ""); 55 } 56 { 57 typedef volatile int T; 58 static_assert(ex::is_volatile_v<T>, ""); 59 static_assert(std::is_same<decltype(ex::is_volatile_v<T>), const bool>::value, ""); 60 static_assert(ex::is_volatile_v<T> == std::is_volatile<T>::value, ""); 61 } 62 { 63 typedef int T; 64 static_assert(!ex::is_volatile_v<T>, ""); 65 static_assert(ex::is_volatile_v<T> == std::is_volatile<T>::value, ""); 66 } 67 { 68 typedef int T; 69 static_assert(ex::is_trivial_v<T>, ""); 70 static_assert(std::is_same<decltype(ex::is_trivial_v<T>), const bool>::value, ""); 71 static_assert(ex::is_trivial_v<T> == std::is_trivial<T>::value, ""); 72 } 73 { 74 typedef int & T; 75 static_assert(!ex::is_trivial_v<T>, ""); 76 static_assert(ex::is_trivial_v<T> == std::is_trivial<T>::value, ""); 77 } 78 { 79 typedef int T; 80 static_assert(ex::is_trivially_copyable_v<T>, ""); 81 static_assert(std::is_same<decltype(ex::is_trivially_copyable_v<T>), const bool>::value, ""); 82 static_assert(ex::is_trivially_copyable_v<T> == std::is_trivially_copyable<T>::value, ""); 83 } 84 { 85 typedef int & T; 86 static_assert(!ex::is_trivially_copyable_v<T>, ""); 87 static_assert(ex::is_trivially_copyable_v<T> == std::is_trivially_copyable<T>::value, ""); 88 } 89 { 90 typedef int T; 91 static_assert(ex::is_standard_layout_v<T>, ""); 92 static_assert(std::is_same<decltype(ex::is_standard_layout_v<T>), const bool>::value, ""); 93 static_assert(ex::is_standard_layout_v<T> == std::is_standard_layout<T>::value, ""); 94 } 95 { 96 typedef int & T; 97 static_assert(!ex::is_standard_layout_v<T>, ""); 98 static_assert(ex::is_standard_layout_v<T> == std::is_standard_layout<T>::value, ""); 99 } 100 { 101 typedef int T; 102 static_assert(ex::is_pod_v<T>, ""); 103 static_assert(std::is_same<decltype(ex::is_pod_v<T>), const bool>::value, ""); 104 static_assert(ex::is_pod_v<T> == std::is_pod<T>::value, ""); 105 } 106 { 107 typedef int & T; 108 static_assert(!ex::is_pod_v<T>, ""); 109 static_assert(ex::is_pod_v<T> == std::is_pod<T>::value, ""); 110 } 111 { 112 typedef int T; 113 static_assert(ex::is_literal_type_v<T>, ""); 114 static_assert(std::is_same<decltype(ex::is_literal_type_v<T>), const bool>::value, ""); 115 static_assert(ex::is_literal_type_v<T> == std::is_literal_type<T>::value, ""); 116 } 117 { 118 typedef non_literal_type T; 119 static_assert(!ex::is_literal_type_v<T>, ""); 120 static_assert(ex::is_literal_type_v<T> == std::is_literal_type<T>::value, ""); 121 } 122 { 123 typedef empty_type T; 124 static_assert(ex::is_empty_v<T>, ""); 125 static_assert(std::is_same<decltype(ex::is_empty_v<T>), const bool>::value, ""); 126 static_assert(ex::is_empty_v<T> == std::is_empty<T>::value, ""); 127 } 128 { 129 typedef int T; 130 static_assert(!ex::is_empty_v<T>, ""); 131 static_assert(ex::is_empty_v<T> == std::is_empty<T>::value, ""); 132 } 133 { 134 typedef polymorphic_type T; 135 static_assert(ex::is_polymorphic_v<T>, ""); 136 static_assert(std::is_same<decltype(ex::is_polymorphic_v<T>), const bool>::value, ""); 137 static_assert(ex::is_polymorphic_v<T> == std::is_polymorphic<T>::value, ""); 138 } 139 { 140 typedef int T; 141 static_assert(!ex::is_polymorphic_v<T>, ""); 142 static_assert(ex::is_polymorphic_v<T> == std::is_polymorphic<T>::value, ""); 143 } 144 { 145 typedef abstract_type T; 146 static_assert(ex::is_abstract_v<T>, ""); 147 static_assert(std::is_same<decltype(ex::is_abstract_v<T>), const bool>::value, ""); 148 static_assert(ex::is_abstract_v<T> == std::is_abstract<T>::value, ""); 149 } 150 { 151 typedef int T; 152 static_assert(!ex::is_abstract_v<T>, ""); 153 static_assert(ex::is_abstract_v<T> == std::is_abstract<T>::value, ""); 154 } 155 { 156 typedef final_type T; 157 static_assert(ex::is_final_v<T>, ""); 158 static_assert(std::is_same<decltype(ex::is_final_v<T>), const bool>::value, ""); 159 static_assert(ex::is_final_v<T> == std::is_final<T>::value, ""); 160 } 161 { 162 typedef int T; 163 static_assert(!ex::is_final_v<T>, ""); 164 static_assert(ex::is_final_v<T> == std::is_final<T>::value, ""); 165 } 166 { 167 typedef int T; 168 static_assert(ex::is_signed_v<T>, ""); 169 static_assert(std::is_same<decltype(ex::is_signed_v<T>), const bool>::value, ""); 170 static_assert(ex::is_signed_v<T> == std::is_signed<T>::value, ""); 171 } 172 { 173 typedef unsigned T; 174 static_assert(!ex::is_signed_v<T>, ""); 175 static_assert(ex::is_signed_v<T> == std::is_signed<T>::value, ""); 176 } 177 { 178 typedef unsigned T; 179 static_assert(ex::is_unsigned_v<T>, ""); 180 static_assert(std::is_same<decltype(ex::is_unsigned_v<T>), const bool>::value, ""); 181 static_assert(ex::is_unsigned_v<T> == std::is_unsigned<T>::value, ""); 182 } 183 { 184 typedef int T; 185 static_assert(!ex::is_unsigned_v<T>, ""); 186 static_assert(ex::is_unsigned_v<T> == std::is_unsigned<T>::value, ""); 187 } 188 } 189 190 void is_constructible_and_assignable_test() 191 { 192 { 193 typedef int T; 194 static_assert(ex::is_constructible_v<T, int>, ""); 195 static_assert(std::is_same<decltype(ex::is_constructible_v<T, int>), const bool>::value, ""); 196 static_assert(ex::is_constructible_v<T, int> == std::is_constructible<T, int>::value, ""); 197 } 198 { 199 typedef void T; 200 static_assert(!ex::is_constructible_v<T, int>, ""); 201 static_assert(ex::is_constructible_v<T, int> == std::is_constructible<T, int>::value, ""); 202 } 203 { 204 typedef int T; 205 static_assert(ex::is_default_constructible_v<T>, ""); 206 static_assert(std::is_same<decltype(ex::is_default_constructible_v<T>), const bool>::value, ""); 207 static_assert(ex::is_default_constructible_v<T> == std::is_default_constructible<T>::value, ""); 208 } 209 { 210 typedef int & T; 211 static_assert(!ex::is_default_constructible_v<T>, ""); 212 static_assert(ex::is_default_constructible_v<T> == std::is_default_constructible<T>::value, ""); 213 } 214 { 215 typedef int T; 216 static_assert(ex::is_copy_constructible_v<T>, ""); 217 static_assert(std::is_same<decltype(ex::is_copy_constructible_v<T>), const bool>::value, ""); 218 static_assert(ex::is_copy_constructible_v<T> == std::is_copy_constructible<T>::value, ""); 219 } 220 { 221 typedef void T; 222 static_assert(!ex::is_copy_constructible_v<T>, ""); 223 static_assert(ex::is_copy_constructible_v<T> == std::is_copy_constructible<T>::value, ""); 224 } 225 { 226 typedef int T; 227 static_assert(ex::is_move_constructible_v<T>, ""); 228 static_assert(std::is_same<decltype(ex::is_move_constructible_v<T>), const bool>::value, ""); 229 static_assert(ex::is_move_constructible_v<T> == std::is_move_constructible<T>::value, ""); 230 } 231 { 232 typedef void T; 233 static_assert(!ex::is_move_constructible_v<T>, ""); 234 static_assert(ex::is_move_constructible_v<T> == std::is_move_constructible<T>::value, ""); 235 } 236 { 237 typedef int & T; 238 typedef int U; 239 static_assert(ex::is_assignable_v<T, U>, ""); 240 static_assert(std::is_same<decltype(ex::is_assignable_v<T, U>), const bool>::value, ""); 241 static_assert(ex::is_assignable_v<T, U> == std::is_assignable<T, U>::value, ""); 242 } 243 { 244 typedef int & T; 245 typedef void U; 246 static_assert(!ex::is_assignable_v<T, U>, ""); 247 static_assert(ex::is_assignable_v<T, U> == std::is_assignable<T, U>::value, ""); 248 } 249 { 250 typedef int T; 251 static_assert(ex::is_copy_assignable_v<T>, ""); 252 static_assert(std::is_same<decltype(ex::is_copy_assignable_v<T>), const bool>::value, ""); 253 static_assert(ex::is_copy_assignable_v<T> == std::is_copy_assignable<T>::value, ""); 254 } 255 { 256 typedef void T; 257 static_assert(!ex::is_copy_assignable_v<T>, ""); 258 static_assert(ex::is_copy_assignable_v<T> == std::is_copy_assignable<T>::value, ""); 259 } 260 { 261 typedef int T; 262 static_assert(ex::is_move_assignable_v<T>, ""); 263 static_assert(std::is_same<decltype(ex::is_move_assignable_v<T>), const bool>::value, ""); 264 static_assert(ex::is_move_assignable_v<T> == std::is_move_assignable<T>::value, ""); 265 } 266 { 267 typedef void T; 268 static_assert(!ex::is_move_assignable_v<T>, ""); 269 static_assert(ex::is_move_assignable_v<T> == std::is_move_assignable<T>::value, ""); 270 } 271 { 272 typedef int T; 273 static_assert(ex::is_destructible_v<T>, ""); 274 static_assert(std::is_same<decltype(ex::is_destructible_v<T>), const bool>::value, ""); 275 static_assert(ex::is_destructible_v<T> == std::is_destructible<T>::value, ""); 276 } 277 { 278 typedef void T; 279 static_assert(!ex::is_destructible_v<T>, ""); 280 static_assert(ex::is_destructible_v<T> == std::is_destructible<T>::value, ""); 281 } 282 } 283 284 void is_trivially_constructible_and_assignable_test() 285 { 286 { 287 typedef int T; 288 static_assert(ex::is_trivially_constructible_v<T, int>, ""); 289 static_assert(std::is_same<decltype(ex::is_trivially_constructible_v<T, int>), const bool>::value, ""); 290 static_assert(ex::is_trivially_constructible_v<T, int> == std::is_constructible<T, int>::value, ""); 291 } 292 { 293 typedef void T; 294 static_assert(!ex::is_trivially_constructible_v<T, int>, ""); 295 static_assert(ex::is_trivially_constructible_v<T, int> == std::is_constructible<T, int>::value, ""); 296 } 297 { 298 typedef int T; 299 static_assert(ex::is_trivially_default_constructible_v<T>, ""); 300 static_assert(std::is_same<decltype(ex::is_trivially_default_constructible_v<T>), const bool>::value, ""); 301 static_assert(ex::is_trivially_default_constructible_v<T> == std::is_default_constructible<T>::value, ""); 302 } 303 { 304 typedef int & T; 305 static_assert(!ex::is_trivially_default_constructible_v<T>, ""); 306 static_assert(ex::is_trivially_default_constructible_v<T> == std::is_default_constructible<T>::value, ""); 307 } 308 { 309 typedef int T; 310 static_assert(ex::is_trivially_copy_constructible_v<T>, ""); 311 static_assert(std::is_same<decltype(ex::is_trivially_copy_constructible_v<T>), const bool>::value, ""); 312 static_assert(ex::is_trivially_copy_constructible_v<T> == std::is_copy_constructible<T>::value, ""); 313 } 314 { 315 typedef void T; 316 static_assert(!ex::is_trivially_copy_constructible_v<T>, ""); 317 static_assert(ex::is_trivially_copy_constructible_v<T> == std::is_copy_constructible<T>::value, ""); 318 } 319 { 320 typedef int T; 321 static_assert(ex::is_trivially_move_constructible_v<T>, ""); 322 static_assert(std::is_same<decltype(ex::is_trivially_move_constructible_v<T>), const bool>::value, ""); 323 static_assert(ex::is_trivially_move_constructible_v<T> == std::is_move_constructible<T>::value, ""); 324 } 325 { 326 typedef void T; 327 static_assert(!ex::is_trivially_move_constructible_v<T>, ""); 328 static_assert(ex::is_trivially_move_constructible_v<T> == std::is_move_constructible<T>::value, ""); 329 } 330 { 331 typedef int & T; 332 typedef int U; 333 static_assert(ex::is_trivially_assignable_v<T, U>, ""); 334 static_assert(std::is_same<decltype(ex::is_trivially_assignable_v<T, U>), const bool>::value, ""); 335 static_assert(ex::is_trivially_assignable_v<T, U> == std::is_assignable<T, U>::value, ""); 336 } 337 { 338 typedef int & T; 339 typedef void U; 340 static_assert(!ex::is_trivially_assignable_v<T, U>, ""); 341 static_assert(ex::is_trivially_assignable_v<T, U> == std::is_assignable<T, U>::value, ""); 342 } 343 { 344 typedef int T; 345 static_assert(ex::is_trivially_copy_assignable_v<T>, ""); 346 static_assert(std::is_same<decltype(ex::is_trivially_copy_assignable_v<T>), const bool>::value, ""); 347 static_assert(ex::is_trivially_copy_assignable_v<T> == std::is_copy_assignable<T>::value, ""); 348 } 349 { 350 typedef void T; 351 static_assert(!ex::is_trivially_copy_assignable_v<T>, ""); 352 static_assert(ex::is_trivially_copy_assignable_v<T> == std::is_copy_assignable<T>::value, ""); 353 } 354 { 355 typedef int T; 356 static_assert(ex::is_trivially_move_assignable_v<T>, ""); 357 static_assert(std::is_same<decltype(ex::is_trivially_move_assignable_v<T>), const bool>::value, ""); 358 static_assert(ex::is_trivially_move_assignable_v<T> == std::is_move_assignable<T>::value, ""); 359 } 360 { 361 typedef void T; 362 static_assert(!ex::is_trivially_move_assignable_v<T>, ""); 363 static_assert(ex::is_trivially_move_assignable_v<T> == std::is_move_assignable<T>::value, ""); 364 } 365 { 366 typedef int T; 367 static_assert(ex::is_trivially_destructible_v<T>, ""); 368 static_assert(std::is_same<decltype(ex::is_trivially_destructible_v<T>), const bool>::value, ""); 369 static_assert(ex::is_trivially_destructible_v<T> == std::is_destructible<T>::value, ""); 370 } 371 { 372 typedef void T; 373 static_assert(!ex::is_trivially_destructible_v<T>, ""); 374 static_assert(ex::is_trivially_destructible_v<T> == std::is_destructible<T>::value, ""); 375 } 376 } 377 378 379 380 void is_nothrow_constructible_and_assignable_test() 381 { 382 { 383 typedef int T; 384 static_assert(ex::is_nothrow_constructible_v<T, int>, ""); 385 static_assert(std::is_same<decltype(ex::is_nothrow_constructible_v<T, int>), const bool>::value, ""); 386 static_assert(ex::is_nothrow_constructible_v<T, int> == std::is_constructible<T, int>::value, ""); 387 } 388 { 389 typedef void T; 390 static_assert(!ex::is_nothrow_constructible_v<T, int>, ""); 391 static_assert(ex::is_nothrow_constructible_v<T, int> == std::is_constructible<T, int>::value, ""); 392 } 393 { 394 typedef int T; 395 static_assert(ex::is_nothrow_default_constructible_v<T>, ""); 396 static_assert(std::is_same<decltype(ex::is_nothrow_default_constructible_v<T>), const bool>::value, ""); 397 static_assert(ex::is_nothrow_default_constructible_v<T> == std::is_default_constructible<T>::value, ""); 398 } 399 { 400 typedef int & T; 401 static_assert(!ex::is_nothrow_default_constructible_v<T>, ""); 402 static_assert(ex::is_nothrow_default_constructible_v<T> == std::is_default_constructible<T>::value, ""); 403 } 404 { 405 typedef int T; 406 static_assert(ex::is_nothrow_copy_constructible_v<T>, ""); 407 static_assert(std::is_same<decltype(ex::is_nothrow_copy_constructible_v<T>), const bool>::value, ""); 408 static_assert(ex::is_nothrow_copy_constructible_v<T> == std::is_copy_constructible<T>::value, ""); 409 } 410 { 411 typedef void T; 412 static_assert(!ex::is_nothrow_copy_constructible_v<T>, ""); 413 static_assert(ex::is_nothrow_copy_constructible_v<T> == std::is_copy_constructible<T>::value, ""); 414 } 415 { 416 typedef int T; 417 static_assert(ex::is_nothrow_move_constructible_v<T>, ""); 418 static_assert(std::is_same<decltype(ex::is_nothrow_move_constructible_v<T>), const bool>::value, ""); 419 static_assert(ex::is_nothrow_move_constructible_v<T> == std::is_move_constructible<T>::value, ""); 420 } 421 { 422 typedef void T; 423 static_assert(!ex::is_nothrow_move_constructible_v<T>, ""); 424 static_assert(ex::is_nothrow_move_constructible_v<T> == std::is_move_constructible<T>::value, ""); 425 } 426 { 427 typedef int & T; 428 typedef int U; 429 static_assert(ex::is_nothrow_assignable_v<T, U>, ""); 430 static_assert(std::is_same<decltype(ex::is_nothrow_assignable_v<T, U>), const bool>::value, ""); 431 static_assert(ex::is_nothrow_assignable_v<T, U> == std::is_assignable<T, U>::value, ""); 432 } 433 { 434 typedef int & T; 435 typedef void U; 436 static_assert(!ex::is_nothrow_assignable_v<T, U>, ""); 437 static_assert(ex::is_nothrow_assignable_v<T, U> == std::is_assignable<T, U>::value, ""); 438 } 439 { 440 typedef int T; 441 static_assert(ex::is_nothrow_copy_assignable_v<T>, ""); 442 static_assert(std::is_same<decltype(ex::is_nothrow_copy_assignable_v<T>), const bool>::value, ""); 443 static_assert(ex::is_nothrow_copy_assignable_v<T> == std::is_copy_assignable<T>::value, ""); 444 } 445 { 446 typedef void T; 447 static_assert(!ex::is_nothrow_copy_assignable_v<T>, ""); 448 static_assert(ex::is_nothrow_copy_assignable_v<T> == std::is_copy_assignable<T>::value, ""); 449 } 450 { 451 typedef int T; 452 static_assert(ex::is_nothrow_move_assignable_v<T>, ""); 453 static_assert(std::is_same<decltype(ex::is_nothrow_move_assignable_v<T>), const bool>::value, ""); 454 static_assert(ex::is_nothrow_move_assignable_v<T> == std::is_move_assignable<T>::value, ""); 455 } 456 { 457 typedef void T; 458 static_assert(!ex::is_nothrow_move_assignable_v<T>, ""); 459 static_assert(ex::is_nothrow_move_assignable_v<T> == std::is_move_assignable<T>::value, ""); 460 } 461 { 462 typedef int T; 463 static_assert(ex::is_nothrow_destructible_v<T>, ""); 464 static_assert(std::is_same<decltype(ex::is_nothrow_destructible_v<T>), const bool>::value, ""); 465 static_assert(ex::is_nothrow_destructible_v<T> == std::is_destructible<T>::value, ""); 466 } 467 { 468 typedef void T; 469 static_assert(!ex::is_nothrow_destructible_v<T>, ""); 470 static_assert(ex::is_nothrow_destructible_v<T> == std::is_destructible<T>::value, ""); 471 } 472 } 473 474 int main() 475 { 476 type_properties_test(); 477 is_constructible_and_assignable_test(); 478 is_trivially_constructible_and_assignable_test(); 479 is_nothrow_constructible_and_assignable_test(); 480 { 481 typedef virtual_dtor_type T; 482 static_assert(ex::has_virtual_destructor_v<T>, ""); 483 static_assert(std::is_same<decltype(ex::has_virtual_destructor_v<T>), const bool>::value, ""); 484 static_assert(ex::has_virtual_destructor_v<T> == std::has_virtual_destructor<T>::value, ""); 485 } 486 { 487 typedef int T; 488 static_assert(!ex::has_virtual_destructor_v<T>, ""); 489 static_assert(ex::has_virtual_destructor_v<T> == std::has_virtual_destructor<T>::value, ""); 490 } 491 } 492 493