1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
14 #include <type_traits>
17 void test_is_destructible()
19 static_assert( std::is_destructible<T>::value, "");
20 static_assert( std::is_destructible<const T>::value, "");
21 static_assert( std::is_destructible<volatile T>::value, "");
22 static_assert( std::is_destructible<const volatile T>::value, "");
26 void test_is_not_destructible()
28 static_assert(!std::is_destructible<T>::value, "");
29 static_assert(!std::is_destructible<const T>::value, "");
30 static_assert(!std::is_destructible<volatile T>::value, "");
31 static_assert(!std::is_destructible<const volatile T>::value, "");
53 typedef void (Function) ();
55 struct PublicAbstract { public: virtual void foo() = 0; };
56 struct ProtectedAbstract { protected: virtual void foo() = 0; };
57 struct PrivateAbstract { private: virtual void foo() = 0; };
59 struct PublicDestructor { public: ~PublicDestructor() {}};
60 struct ProtectedDestructor { protected: ~ProtectedDestructor() {}};
61 struct PrivateDestructor { private: ~PrivateDestructor() {}};
63 struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}};
64 struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}};
65 struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}};
67 struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; };
68 struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; };
69 struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; };
71 struct DeletedPublicDestructor { public: ~DeletedPublicDestructor() = delete; };
72 struct DeletedProtectedDestructor { protected: ~DeletedProtectedDestructor() = delete; };
73 struct DeletedPrivateDestructor { private: ~DeletedPrivateDestructor() = delete; };
75 struct DeletedVirtualPublicDestructor { public: virtual ~DeletedVirtualPublicDestructor() = delete; };
76 struct DeletedVirtualProtectedDestructor { protected: virtual ~DeletedVirtualProtectedDestructor() = delete; };
77 struct DeletedVirtualPrivateDestructor { private: virtual ~DeletedVirtualPrivateDestructor() = delete; };
82 test_is_destructible<A>();
83 test_is_destructible<int&>();
84 test_is_destructible<Union>();
85 test_is_destructible<Empty>();
86 test_is_destructible<int>();
87 test_is_destructible<double>();
88 test_is_destructible<int*>();
89 test_is_destructible<const int*>();
90 test_is_destructible<char[3]>();
91 test_is_destructible<bit_zero>();
92 test_is_destructible<int[3]>();
93 test_is_destructible<ProtectedAbstract>();
94 test_is_destructible<PublicAbstract>();
95 test_is_destructible<PrivateAbstract>();
96 test_is_destructible<PublicDestructor>();
97 test_is_destructible<VirtualPublicDestructor>();
98 test_is_destructible<PurePublicDestructor>();
100 test_is_not_destructible<int[]>();
101 test_is_not_destructible<void>();
103 test_is_not_destructible<ProtectedDestructor>();
104 test_is_not_destructible<PrivateDestructor>();
105 test_is_not_destructible<VirtualProtectedDestructor>();
106 test_is_not_destructible<VirtualPrivateDestructor>();
107 test_is_not_destructible<PureProtectedDestructor>();
108 test_is_not_destructible<PurePrivateDestructor>();
109 test_is_not_destructible<DeletedPublicDestructor>();
110 test_is_not_destructible<DeletedProtectedDestructor>();
111 test_is_not_destructible<DeletedPrivateDestructor>();
113 // test_is_not_destructible<DeletedVirtualPublicDestructor>(); // currently fails due to clang bug #20268
114 test_is_not_destructible<DeletedVirtualProtectedDestructor>();
115 test_is_not_destructible<DeletedVirtualPrivateDestructor>();
117 #if __has_feature(cxx_access_control_sfinae)
118 test_is_not_destructible<NotEmpty>();
120 test_is_not_destructible<Function>();