//===----------------------------------------------------------------------===// // // 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_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_destructible() { static_assert( std::is_destructible::value, ""); static_assert( std::is_destructible::value, ""); static_assert( std::is_destructible::value, ""); static_assert( std::is_destructible::value, ""); #if TEST_STD_VER > 14 static_assert( std::is_destructible_v, ""); static_assert( std::is_destructible_v, ""); static_assert( std::is_destructible_v, ""); static_assert( std::is_destructible_v, ""); #endif } template void test_is_not_destructible() { static_assert(!std::is_destructible::value, ""); static_assert(!std::is_destructible::value, ""); static_assert(!std::is_destructible::value, ""); static_assert(!std::is_destructible::value, ""); #if TEST_STD_VER > 14 static_assert(!std::is_destructible_v, ""); static_assert(!std::is_destructible_v, ""); static_assert(!std::is_destructible_v, ""); static_assert(!std::is_destructible_v, ""); #endif } class Empty {}; class NotEmpty { virtual ~NotEmpty(); }; union Union {}; struct bit_zero { int : 0; }; struct A { ~A(); }; typedef void (Function) (); struct PublicAbstract { public: virtual void foo() = 0; }; struct ProtectedAbstract { protected: virtual void foo() = 0; }; struct PrivateAbstract { private: virtual void foo() = 0; }; 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; }; #if TEST_STD_VER >= 11 struct DeletedPublicDestructor { public: ~DeletedPublicDestructor() = delete; }; struct DeletedProtectedDestructor { protected: ~DeletedProtectedDestructor() = delete; }; struct DeletedPrivateDestructor { private: ~DeletedPrivateDestructor() = delete; }; struct DeletedVirtualPublicDestructor { public: virtual ~DeletedVirtualPublicDestructor() = delete; }; struct DeletedVirtualProtectedDestructor { protected: virtual ~DeletedVirtualProtectedDestructor() = delete; }; struct DeletedVirtualPrivateDestructor { private: virtual ~DeletedVirtualPrivateDestructor() = delete; }; #endif int main(int, char**) { test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_destructible(); test_is_not_destructible(); test_is_not_destructible(); test_is_not_destructible(); #if TEST_STD_VER >= 11 // Test access controlled destructors test_is_not_destructible(); test_is_not_destructible(); test_is_not_destructible(); test_is_not_destructible(); test_is_not_destructible(); test_is_not_destructible(); // Test deleted constructors test_is_not_destructible(); test_is_not_destructible(); test_is_not_destructible(); //test_is_not_destructible(); // previously failed due to clang bug #20268 test_is_not_destructible(); test_is_not_destructible(); // Test private destructors test_is_not_destructible(); #endif return 0; }