| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // type_traits |
| 10 | |
| 11 | // is_default_constructible |
| 12 | |
| 13 | #include <type_traits> |
| 14 | #include "test_macros.h" |
| 15 | |
| 16 | template <class T> |
| 17 | void test_is_default_constructible() |
| 18 | { |
| 19 | static_assert( std::is_default_constructible<T>::value, "" ); |
| 20 | static_assert( std::is_default_constructible<const T>::value, "" ); |
| 21 | static_assert( std::is_default_constructible<volatile T>::value, "" ); |
| 22 | static_assert( std::is_default_constructible<const volatile T>::value, "" ); |
| 23 | #if TEST_STD_VER > 14 |
| 24 | static_assert( std::is_default_constructible_v<T>, "" ); |
| 25 | static_assert( std::is_default_constructible_v<const T>, "" ); |
| 26 | static_assert( std::is_default_constructible_v<volatile T>, "" ); |
| 27 | static_assert( std::is_default_constructible_v<const volatile T>, "" ); |
| 28 | #endif |
| 29 | } |
| 30 | |
| 31 | template <class T> |
| 32 | void test_is_not_default_constructible() |
| 33 | { |
| 34 | static_assert(!std::is_default_constructible<T>::value, "" ); |
| 35 | static_assert(!std::is_default_constructible<const T>::value, "" ); |
| 36 | static_assert(!std::is_default_constructible<volatile T>::value, "" ); |
| 37 | static_assert(!std::is_default_constructible<const volatile T>::value, "" ); |
| 38 | #if TEST_STD_VER > 14 |
| 39 | static_assert(!std::is_default_constructible_v<T>, "" ); |
| 40 | static_assert(!std::is_default_constructible_v<const T>, "" ); |
| 41 | static_assert(!std::is_default_constructible_v<volatile T>, "" ); |
| 42 | static_assert(!std::is_default_constructible_v<const volatile T>, "" ); |
| 43 | #endif |
| 44 | } |
| 45 | |
| 46 | class Empty |
| 47 | { |
| 48 | }; |
| 49 | |
| 50 | class NoDefaultConstructor |
| 51 | { |
| 52 | NoDefaultConstructor(int) {} |
| 53 | }; |
| 54 | |
| 55 | class NotEmpty |
| 56 | { |
| 57 | public: |
| 58 | virtual ~NotEmpty(); |
| 59 | }; |
| 60 | |
| 61 | union Union {}; |
| 62 | |
| 63 | struct bit_zero |
| 64 | { |
| 65 | int : 0; |
| 66 | }; |
| 67 | |
| 68 | class Abstract |
| 69 | { |
| 70 | public: |
| 71 | virtual ~Abstract() = 0; |
| 72 | }; |
| 73 | |
| 74 | struct A |
| 75 | { |
| 76 | A(); |
| 77 | }; |
| 78 | |
| 79 | class B |
| 80 | { |
| 81 | B(); |
| 82 | }; |
| 83 | |
| 84 | int main(int, char**) |
| 85 | { |
| 86 | test_is_default_constructible<A>(); |
| 87 | test_is_default_constructible<Union>(); |
| 88 | test_is_default_constructible<Empty>(); |
| 89 | test_is_default_constructible<int>(); |
| 90 | test_is_default_constructible<double>(); |
| 91 | test_is_default_constructible<int*>(); |
| 92 | test_is_default_constructible<const int*>(); |
| 93 | test_is_default_constructible<char[3]>(); |
| 94 | test_is_default_constructible<char[5][3]>(); |
| 95 | |
| 96 | test_is_default_constructible<NotEmpty>(); |
| 97 | test_is_default_constructible<bit_zero>(); |
| 98 | |
| 99 | test_is_not_default_constructible<void>(); |
| 100 | test_is_not_default_constructible<int&>(); |
| 101 | test_is_not_default_constructible<char[]>(); |
| 102 | test_is_not_default_constructible<char[][3]>(); |
| 103 | |
| 104 | test_is_not_default_constructible<Abstract>(); |
| 105 | test_is_not_default_constructible<NoDefaultConstructor>(); |
| 106 | #if TEST_STD_VER >= 11 |
| 107 | test_is_not_default_constructible<B>(); |
| 108 | test_is_not_default_constructible<int&&>(); |
| 109 | test_is_not_default_constructible<void()>(); |
| 110 | test_is_not_default_constructible<void() const> (); |
| 111 | test_is_not_default_constructible<void() volatile> (); |
| 112 | test_is_not_default_constructible<void() &> (); |
| 113 | test_is_not_default_constructible<void() &&> (); |
| 114 | #endif |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |