//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // type_traits // is_nothrow_destructible // Prevent warning when testing the Abstract test type. #if defined(__clang__) #pragma clang diagnostic ignored "-Wdelete-non-virtual-dtor" #endif #include #include "test_macros.h" template void test_is_nothrow_destructible() { static_assert( std::is_nothrow_destructible::value, ""); static_assert( std::is_nothrow_destructible::value, ""); static_assert( std::is_nothrow_destructible::value, ""); static_assert( std::is_nothrow_destructible::value, ""); #if TEST_STD_VER > 14 static_assert( std::is_nothrow_destructible_v, ""); static_assert( std::is_nothrow_destructible_v, ""); static_assert( std::is_nothrow_destructible_v, ""); static_assert( std::is_nothrow_destructible_v, ""); #endif } template void test_is_not_nothrow_destructible() { static_assert(!std::is_nothrow_destructible::value, ""); static_assert(!std::is_nothrow_destructible::value, ""); static_assert(!std::is_nothrow_destructible::value, ""); static_assert(!std::is_nothrow_destructible::value, ""); #if TEST_STD_VER > 14 static_assert(!std::is_nothrow_destructible_v, ""); static_assert(!std::is_nothrow_destructible_v, ""); static_assert(!std::is_nothrow_destructible_v, ""); static_assert(!std::is_nothrow_destructible_v, ""); #endif } struct PublicDestructor { public: ~PublicDestructor() {}}; struct ProtectedDestructor { protected: ~ProtectedDestructor() {}}; struct PrivateDestructor { private: ~PrivateDestructor() {}}; struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}}; struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}}; struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}}; struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; }; struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; }; struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; }; class Empty { }; union Union {}; struct bit_zero { int : 0; }; class Abstract { virtual void foo() = 0; }; int main(int, char**) { test_is_not_nothrow_destructible(); test_is_not_nothrow_destructible(); test_is_not_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); #if TEST_STD_VER >= 11 // requires noexcept. These are all destructible. test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); test_is_nothrow_destructible(); #endif // requires access control test_is_not_nothrow_destructible(); test_is_not_nothrow_destructible(); test_is_not_nothrow_destructible(); test_is_not_nothrow_destructible(); test_is_not_nothrow_destructible(); test_is_not_nothrow_destructible(); return 0; }