blob: fae9557dbe3e01759a655319d4530a5574f32fa5 [file] [log] [blame]
Howard Hinnant1468b662010-11-19 22:17:28 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// type_traits
11
12// is_destructible
13
14#include <type_traits>
Dan Albert1d4a1ed2016-05-25 22:36:09 -070015
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000016#include "test_macros.h"
17
Marshall Clow933afa92013-07-04 00:10:01 +000018template <class T>
Howard Hinnant1468b662010-11-19 22:17:28 +000019void test_is_destructible()
20{
Marshall Clow933afa92013-07-04 00:10:01 +000021 static_assert( std::is_destructible<T>::value, "");
22 static_assert( std::is_destructible<const T>::value, "");
23 static_assert( std::is_destructible<volatile T>::value, "");
24 static_assert( std::is_destructible<const volatile T>::value, "");
25}
26
27template <class T>
28void test_is_not_destructible()
29{
30 static_assert(!std::is_destructible<T>::value, "");
31 static_assert(!std::is_destructible<const T>::value, "");
32 static_assert(!std::is_destructible<volatile T>::value, "");
33 static_assert(!std::is_destructible<const volatile T>::value, "");
Howard Hinnant1468b662010-11-19 22:17:28 +000034}
35
Marshall Clow2b44e3d2014-07-16 15:51:50 +000036class Empty {};
Howard Hinnant1468b662010-11-19 22:17:28 +000037
38class NotEmpty
39{
40 virtual ~NotEmpty();
41};
42
43union Union {};
44
45struct bit_zero
46{
47 int : 0;
48};
49
Howard Hinnant1468b662010-11-19 22:17:28 +000050struct A
51{
52 ~A();
53};
54
Howard Hinnantd1794072013-08-30 19:12:42 +000055typedef void (Function) ();
56
Marshall Clow2b44e3d2014-07-16 15:51:50 +000057struct PublicAbstract { public: virtual void foo() = 0; };
58struct ProtectedAbstract { protected: virtual void foo() = 0; };
59struct PrivateAbstract { private: virtual void foo() = 0; };
60
61struct PublicDestructor { public: ~PublicDestructor() {}};
62struct ProtectedDestructor { protected: ~ProtectedDestructor() {}};
63struct PrivateDestructor { private: ~PrivateDestructor() {}};
64
65struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}};
66struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}};
67struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}};
68
69struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; };
70struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; };
71struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; };
72
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000073#if TEST_STD_VER >= 11
Marshall Clow2b44e3d2014-07-16 15:51:50 +000074struct DeletedPublicDestructor { public: ~DeletedPublicDestructor() = delete; };
75struct DeletedProtectedDestructor { protected: ~DeletedProtectedDestructor() = delete; };
76struct DeletedPrivateDestructor { private: ~DeletedPrivateDestructor() = delete; };
77
78struct DeletedVirtualPublicDestructor { public: virtual ~DeletedVirtualPublicDestructor() = delete; };
79struct DeletedVirtualProtectedDestructor { protected: virtual ~DeletedVirtualProtectedDestructor() = delete; };
80struct DeletedVirtualPrivateDestructor { private: virtual ~DeletedVirtualPrivateDestructor() = delete; };
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000081#endif
Marshall Clow2b44e3d2014-07-16 15:51:50 +000082
83
Howard Hinnant1468b662010-11-19 22:17:28 +000084int main()
85{
Marshall Clow933afa92013-07-04 00:10:01 +000086 test_is_destructible<A>();
87 test_is_destructible<int&>();
88 test_is_destructible<Union>();
89 test_is_destructible<Empty>();
90 test_is_destructible<int>();
91 test_is_destructible<double>();
92 test_is_destructible<int*>();
93 test_is_destructible<const int*>();
94 test_is_destructible<char[3]>();
95 test_is_destructible<bit_zero>();
Howard Hinnant80e19ac2013-08-09 16:53:45 +000096 test_is_destructible<int[3]>();
Marshall Clow2b44e3d2014-07-16 15:51:50 +000097 test_is_destructible<ProtectedAbstract>();
98 test_is_destructible<PublicAbstract>();
99 test_is_destructible<PrivateAbstract>();
100 test_is_destructible<PublicDestructor>();
101 test_is_destructible<VirtualPublicDestructor>();
102 test_is_destructible<PurePublicDestructor>();
Marshall Clow933afa92013-07-04 00:10:01 +0000103
Howard Hinnant80e19ac2013-08-09 16:53:45 +0000104 test_is_not_destructible<int[]>();
Marshall Clow933afa92013-07-04 00:10:01 +0000105 test_is_not_destructible<void>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +0000106 test_is_not_destructible<Function>();
Marshall Clow2b44e3d2014-07-16 15:51:50 +0000107
Eric Fiselier12c6d9c2015-07-18 16:43:58 +0000108#if TEST_STD_VER >= 11
109 // Test access controlled destructors
Marshall Clow2b44e3d2014-07-16 15:51:50 +0000110 test_is_not_destructible<ProtectedDestructor>();
111 test_is_not_destructible<PrivateDestructor>();
112 test_is_not_destructible<VirtualProtectedDestructor>();
113 test_is_not_destructible<VirtualPrivateDestructor>();
114 test_is_not_destructible<PureProtectedDestructor>();
115 test_is_not_destructible<PurePrivateDestructor>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +0000116
117 // Test deleted constructors
Marshall Clow2b44e3d2014-07-16 15:51:50 +0000118 test_is_not_destructible<DeletedPublicDestructor>();
119 test_is_not_destructible<DeletedProtectedDestructor>();
120 test_is_not_destructible<DeletedPrivateDestructor>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +0000121 //test_is_not_destructible<DeletedVirtualPublicDestructor>(); // previously failed due to clang bug #20268
Marshall Clow2b44e3d2014-07-16 15:51:50 +0000122 test_is_not_destructible<DeletedVirtualProtectedDestructor>();
123 test_is_not_destructible<DeletedVirtualPrivateDestructor>();
124
Eric Fiselier12c6d9c2015-07-18 16:43:58 +0000125 // Test private destructors
Marshall Clow933afa92013-07-04 00:10:01 +0000126 test_is_not_destructible<NotEmpty>();
127#endif
Eric Fiselier12c6d9c2015-07-18 16:43:58 +0000128
Howard Hinnant1468b662010-11-19 22:17:28 +0000129}