[SandboxVec][Utils] Implement Utils::verifyFunction() (#124356)
[llvm-project.git] / libcxx / test / std / utilities / meta / meta.unary / meta.unary.prop / is_nothrow_destructible.pass.cpp
blob742c9e9288de58d987145c1fda9c8209d986c5a9
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 //===----------------------------------------------------------------------===//
9 // type_traits
11 // is_nothrow_destructible
13 #include <type_traits>
14 #include "test_macros.h"
16 template <class T>
17 void test_is_nothrow_destructible()
19 static_assert( std::is_nothrow_destructible<T>::value, "");
20 static_assert( std::is_nothrow_destructible<const T>::value, "");
21 static_assert( std::is_nothrow_destructible<volatile T>::value, "");
22 static_assert( std::is_nothrow_destructible<const volatile T>::value, "");
23 #if TEST_STD_VER > 14
24 static_assert( std::is_nothrow_destructible_v<T>, "");
25 static_assert( std::is_nothrow_destructible_v<const T>, "");
26 static_assert( std::is_nothrow_destructible_v<volatile T>, "");
27 static_assert( std::is_nothrow_destructible_v<const volatile T>, "");
28 #endif
31 template <class T>
32 void test_is_not_nothrow_destructible()
34 static_assert(!std::is_nothrow_destructible<T>::value, "");
35 static_assert(!std::is_nothrow_destructible<const T>::value, "");
36 static_assert(!std::is_nothrow_destructible<volatile T>::value, "");
37 static_assert(!std::is_nothrow_destructible<const volatile T>::value, "");
38 #if TEST_STD_VER > 14
39 static_assert(!std::is_nothrow_destructible_v<T>, "");
40 static_assert(!std::is_nothrow_destructible_v<const T>, "");
41 static_assert(!std::is_nothrow_destructible_v<volatile T>, "");
42 static_assert(!std::is_nothrow_destructible_v<const volatile T>, "");
43 #endif
47 struct PublicDestructor { public: ~PublicDestructor() {}};
48 struct ProtectedDestructor { protected: ~ProtectedDestructor() {}};
49 struct PrivateDestructor { private: ~PrivateDestructor() {}};
51 struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}};
52 struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}};
53 struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}};
55 struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; };
56 struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; };
57 struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; };
59 struct ExplicitlyNoThrowDestructor {
60 ~ExplicitlyNoThrowDestructor() TEST_NOEXCEPT {}
63 class Empty
68 union Union {};
70 struct bit_zero
72 int : 0;
75 class Abstract
77 virtual void foo() = 0;
81 int main(int, char**)
83 test_is_not_nothrow_destructible<void>();
84 test_is_not_nothrow_destructible<char[]>();
85 test_is_not_nothrow_destructible<char[][3]>();
87 test_is_nothrow_destructible<int&>();
88 test_is_nothrow_destructible<int>();
89 test_is_nothrow_destructible<double>();
90 test_is_nothrow_destructible<int*>();
91 test_is_nothrow_destructible<const int*>();
92 test_is_nothrow_destructible<char[3]>();
94 #if TEST_STD_VER >= 11
95 // requires noexcept. These are all destructible.
96 test_is_nothrow_destructible<PublicDestructor>();
97 test_is_nothrow_destructible<VirtualPublicDestructor>();
98 test_is_nothrow_destructible<PurePublicDestructor>();
99 #endif
100 test_is_nothrow_destructible<ExplicitlyNoThrowDestructor>();
101 test_is_nothrow_destructible<bit_zero>();
102 test_is_nothrow_destructible<Abstract>();
103 test_is_nothrow_destructible<Empty>();
104 test_is_nothrow_destructible<Union>();
105 // requires access control
106 test_is_not_nothrow_destructible<ProtectedDestructor>();
107 test_is_not_nothrow_destructible<PrivateDestructor>();
108 test_is_not_nothrow_destructible<VirtualProtectedDestructor>();
109 test_is_not_nothrow_destructible<VirtualPrivateDestructor>();
110 test_is_not_nothrow_destructible<PureProtectedDestructor>();
111 test_is_not_nothrow_destructible<PurePrivateDestructor>();
114 return 0;