brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.1 KiB · 87abf32 Raw
143 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// type_traits10 11// is_destructible12 13#include <type_traits>14#include "test_macros.h"15 16 17template <class T>18void test_is_destructible()19{20    static_assert( std::is_destructible<T>::value, "");21    static_assert( std::is_destructible<const T>::value, "");22    static_assert( std::is_destructible<volatile T>::value, "");23    static_assert( std::is_destructible<const volatile T>::value, "");24#if TEST_STD_VER > 1425    static_assert( std::is_destructible_v<T>, "");26    static_assert( std::is_destructible_v<const T>, "");27    static_assert( std::is_destructible_v<volatile T>, "");28    static_assert( std::is_destructible_v<const volatile T>, "");29#endif30}31 32template <class T>33void test_is_not_destructible()34{35    static_assert(!std::is_destructible<T>::value, "");36    static_assert(!std::is_destructible<const T>::value, "");37    static_assert(!std::is_destructible<volatile T>::value, "");38    static_assert(!std::is_destructible<const volatile T>::value, "");39#if TEST_STD_VER > 1440    static_assert(!std::is_destructible_v<T>, "");41    static_assert(!std::is_destructible_v<const T>, "");42    static_assert(!std::is_destructible_v<volatile T>, "");43    static_assert(!std::is_destructible_v<const volatile T>, "");44#endif45}46 47class Empty {};48 49class NotEmpty50{51    virtual ~NotEmpty();52};53 54union Union {};55 56struct bit_zero57{58    int :  0;59};60 61struct A62{63    ~A();64};65 66typedef void (Function) ();67 68struct PublicAbstract                    { public:    virtual void foo() = 0; };69struct ProtectedAbstract                 { protected: virtual void foo() = 0; };70struct PrivateAbstract                   { private:   virtual void foo() = 0; };71 72struct PublicDestructor                  { public:    ~PublicDestructor() {}};73struct ProtectedDestructor               { protected: ~ProtectedDestructor() {}};74struct PrivateDestructor                 { private:   ~PrivateDestructor() {}};75 76struct VirtualPublicDestructor           { public:    virtual ~VirtualPublicDestructor() {}};77struct VirtualProtectedDestructor        { protected: virtual ~VirtualProtectedDestructor() {}};78struct VirtualPrivateDestructor          { private:   virtual ~VirtualPrivateDestructor() {}};79 80struct PurePublicDestructor              { public:    virtual ~PurePublicDestructor() = 0; };81struct PureProtectedDestructor           { protected: virtual ~PureProtectedDestructor() = 0; };82struct PurePrivateDestructor             { private:   virtual ~PurePrivateDestructor() = 0; };83 84#if TEST_STD_VER >= 1185struct DeletedPublicDestructor           { public:    ~DeletedPublicDestructor() = delete; };86struct DeletedProtectedDestructor        { protected: ~DeletedProtectedDestructor() = delete; };87struct DeletedPrivateDestructor          { private:   ~DeletedPrivateDestructor() = delete; };88 89struct DeletedVirtualPublicDestructor    { public:    virtual ~DeletedVirtualPublicDestructor() = delete; };90struct DeletedVirtualProtectedDestructor { protected: virtual ~DeletedVirtualProtectedDestructor() = delete; };91struct DeletedVirtualPrivateDestructor   { private:   virtual ~DeletedVirtualPrivateDestructor() = delete; };92#endif93 94 95int main(int, char**)96{97    test_is_destructible<A>();98    test_is_destructible<int&>();99    test_is_destructible<Union>();100    test_is_destructible<Empty>();101    test_is_destructible<int>();102    test_is_destructible<double>();103    test_is_destructible<int*>();104    test_is_destructible<const int*>();105    test_is_destructible<char[3]>();106    test_is_destructible<bit_zero>();107    test_is_destructible<int[3]>();108    test_is_destructible<ProtectedAbstract>();109    test_is_destructible<PublicAbstract>();110    test_is_destructible<PrivateAbstract>();111    test_is_destructible<PublicDestructor>();112    test_is_destructible<VirtualPublicDestructor>();113    test_is_destructible<PurePublicDestructor>();114 115    test_is_not_destructible<int[]>();116    test_is_not_destructible<void>();117    test_is_not_destructible<Function>();118 119#if TEST_STD_VER >= 11120    // Test access controlled destructors121    test_is_not_destructible<ProtectedDestructor>();122    test_is_not_destructible<PrivateDestructor>();123    test_is_not_destructible<VirtualProtectedDestructor>();124    test_is_not_destructible<VirtualPrivateDestructor>();125    test_is_not_destructible<PureProtectedDestructor>();126    test_is_not_destructible<PurePrivateDestructor>();127 128    // Test deleted constructors129    test_is_not_destructible<DeletedPublicDestructor>();130    test_is_not_destructible<DeletedProtectedDestructor>();131    test_is_not_destructible<DeletedPrivateDestructor>();132    //test_is_not_destructible<DeletedVirtualPublicDestructor>(); // previously failed due to clang bug #20268133    test_is_not_destructible<DeletedVirtualProtectedDestructor>();134    test_is_not_destructible<DeletedVirtualPrivateDestructor>();135 136    // Test private destructors137    test_is_not_destructible<NotEmpty>();138#endif139 140 141  return 0;142}143