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 // is_nothrow_destructible 13 14 #include <type_traits> 15 #include "test_macros.h" 16 17 template <class T> 18 void test_is_nothrow_destructible() 19 { 20 static_assert( std::is_nothrow_destructible<T>::value, ""); 21 static_assert( std::is_nothrow_destructible<const T>::value, ""); 22 static_assert( std::is_nothrow_destructible<volatile T>::value, ""); 23 static_assert( std::is_nothrow_destructible<const volatile T>::value, ""); 24 #if TEST_STD_VER > 14 25 static_assert( std::is_nothrow_destructible_v<T>, ""); 26 static_assert( std::is_nothrow_destructible_v<const T>, ""); 27 static_assert( std::is_nothrow_destructible_v<volatile T>, ""); 28 static_assert( std::is_nothrow_destructible_v<const volatile T>, ""); 29 #endif 30 } 31 32 template <class T> 33 void test_is_not_nothrow_destructible() 34 { 35 static_assert(!std::is_nothrow_destructible<T>::value, ""); 36 static_assert(!std::is_nothrow_destructible<const T>::value, ""); 37 static_assert(!std::is_nothrow_destructible<volatile T>::value, ""); 38 static_assert(!std::is_nothrow_destructible<const volatile T>::value, ""); 39 #if TEST_STD_VER > 14 40 static_assert(!std::is_nothrow_destructible_v<T>, ""); 41 static_assert(!std::is_nothrow_destructible_v<const T>, ""); 42 static_assert(!std::is_nothrow_destructible_v<volatile T>, ""); 43 static_assert(!std::is_nothrow_destructible_v<const volatile T>, ""); 44 #endif 45 } 46 47 48 struct PublicDestructor { public: ~PublicDestructor() {}}; 49 struct ProtectedDestructor { protected: ~ProtectedDestructor() {}}; 50 struct PrivateDestructor { private: ~PrivateDestructor() {}}; 51 52 struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}}; 53 struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}}; 54 struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}}; 55 56 struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; }; 57 struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; }; 58 struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; }; 59 60 class Empty 61 { 62 }; 63 64 65 union Union {}; 66 67 struct bit_zero 68 { 69 int : 0; 70 }; 71 72 class Abstract 73 { 74 virtual void foo() = 0; 75 }; 76 77 78 int main() 79 { 80 test_is_not_nothrow_destructible<void>(); 81 test_is_not_nothrow_destructible<char[]>(); 82 test_is_not_nothrow_destructible<char[][3]>(); 83 84 test_is_nothrow_destructible<int&>(); 85 test_is_nothrow_destructible<int>(); 86 test_is_nothrow_destructible<double>(); 87 test_is_nothrow_destructible<int*>(); 88 test_is_nothrow_destructible<const int*>(); 89 test_is_nothrow_destructible<char[3]>(); 90 91 #if TEST_STD_VER >= 11 92 // requires noexcept. These are all destructible. 93 test_is_nothrow_destructible<PublicDestructor>(); 94 test_is_nothrow_destructible<VirtualPublicDestructor>(); 95 test_is_nothrow_destructible<PurePublicDestructor>(); 96 test_is_nothrow_destructible<bit_zero>(); 97 test_is_nothrow_destructible<Abstract>(); 98 test_is_nothrow_destructible<Empty>(); 99 test_is_nothrow_destructible<Union>(); 100 101 // requires access control 102 test_is_not_nothrow_destructible<ProtectedDestructor>(); 103 test_is_not_nothrow_destructible<PrivateDestructor>(); 104 test_is_not_nothrow_destructible<VirtualProtectedDestructor>(); 105 test_is_not_nothrow_destructible<VirtualPrivateDestructor>(); 106 test_is_not_nothrow_destructible<PureProtectedDestructor>(); 107 test_is_not_nothrow_destructible<PurePrivateDestructor>(); 108 #endif 109 } 110