|
| 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 | +// type_traits |
| 11 | + |
| 12 | +// __libcpp_is_trivially_relocatable |
| 13 | +// __libcpp_is_trivially_relocatable_v |
| 14 | + |
| 15 | +#include <memory> |
| 16 | +#include <type_traits> |
| 17 | +#include "test_macros.h" |
| 18 | + |
| 19 | + |
| 20 | +template <class T> |
| 21 | +void test_is_trivially_relocatable() |
| 22 | +{ |
| 23 | + static_assert(std::__libcpp_is_trivially_relocatable<T>::value, ""); |
| 24 | +#if TEST_STD_VER > 14 |
| 25 | + static_assert(std::__libcpp_is_trivially_relocatable_v<T>, ""); |
| 26 | +#endif |
| 27 | +} |
| 28 | + |
| 29 | +template <class T> |
| 30 | +void test_is_not_trivially_relocatable() |
| 31 | +{ |
| 32 | + static_assert(!std::__libcpp_is_trivially_relocatable<T>::value, ""); |
| 33 | +#if TEST_STD_VER > 14 |
| 34 | + static_assert(!std::__libcpp_is_trivially_relocatable_v<T>, ""); |
| 35 | +#endif |
| 36 | +} |
| 37 | + |
| 38 | +class Empty {}; |
| 39 | + |
| 40 | +class Abstract { |
| 41 | +public: |
| 42 | + virtual ~Abstract() = 0; |
| 43 | +}; |
| 44 | + |
| 45 | +class Polymorphic { |
| 46 | +public: |
| 47 | + virtual ~Polymorphic() = default; |
| 48 | +}; |
| 49 | + |
| 50 | +union Union {}; |
| 51 | + |
| 52 | +struct bit_zero { |
| 53 | + int : 0; |
| 54 | +}; |
| 55 | + |
| 56 | +struct CopyCtor { |
| 57 | + CopyCtor(const CopyCtor&); |
| 58 | +}; |
| 59 | + |
| 60 | +#if TEST_STD_VER >= 11 |
| 61 | +struct MoveOnly1 { |
| 62 | + MoveOnly1(MoveOnly1&&); |
| 63 | +}; |
| 64 | + |
| 65 | +struct MoveOnly2 { |
| 66 | + MoveOnly2(MoveOnly2&&) = default; |
| 67 | +}; |
| 68 | +#endif |
| 69 | + |
| 70 | +int main(int, char**) |
| 71 | +{ |
| 72 | + test_is_not_trivially_relocatable<void>(); |
| 73 | + test_is_not_trivially_relocatable<const void>(); |
| 74 | + test_is_not_trivially_relocatable<Abstract>(); |
| 75 | + test_is_not_trivially_relocatable<Polymorphic>(); |
| 76 | + test_is_not_trivially_relocatable<CopyCtor>(); |
| 77 | + |
| 78 | + test_is_trivially_relocatable<Union>(); |
| 79 | + test_is_trivially_relocatable<Empty>(); |
| 80 | + test_is_trivially_relocatable<double>(); |
| 81 | + test_is_trivially_relocatable<int*>(); |
| 82 | + test_is_trivially_relocatable<const int*>(); |
| 83 | + test_is_trivially_relocatable<bit_zero>(); |
| 84 | + |
| 85 | + test_is_trivially_relocatable<int>(); |
| 86 | + test_is_trivially_relocatable<const int>(); |
| 87 | + test_is_trivially_relocatable<volatile int>(); |
| 88 | + test_is_trivially_relocatable<const volatile int>(); |
| 89 | + |
| 90 | + test_is_trivially_relocatable<int[]>(); |
| 91 | + test_is_trivially_relocatable<int[10]>(); |
| 92 | + test_is_trivially_relocatable<int[][2]>(); |
| 93 | + test_is_trivially_relocatable<int[1][2]>(); |
| 94 | + |
| 95 | +#if TEST_STD_VER >= 11 |
| 96 | + test_is_not_trivially_relocatable<MoveOnly1>(); |
| 97 | + test_is_not_trivially_relocatable<const MoveOnly1>(); |
| 98 | + test_is_trivially_relocatable<MoveOnly2>(); |
| 99 | + test_is_trivially_relocatable<const MoveOnly2>(); |
| 100 | +#endif |
| 101 | + |
| 102 | + return 0; |
| 103 | +} |
0 commit comments