1 //===----------------------------------------------------------------------===//
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>
15 
16 template <class T>
test_is_destructible()17 void test_is_destructible()
18 {
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, "");
23 }
24 
25 template <class T>
test_is_not_destructible()26 void test_is_not_destructible()
27 {
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, "");
32 }
33 
34 class Empty {};
35 
36 class NotEmpty
37 {
38     virtual ~NotEmpty();
39 };
40 
41 union Union {};
42 
43 struct bit_zero
44 {
45     int :  0;
46 };
47 
48 struct A
49 {
50     ~A();
51 };
52 
53 typedef void (Function) ();
54 
55 struct PublicAbstract                    { public:    virtual void foo() = 0; };
56 struct ProtectedAbstract                 { protected: virtual void foo() = 0; };
57 struct PrivateAbstract                   { private:   virtual void foo() = 0; };
58 
~PublicDestructorPublicDestructor59 struct PublicDestructor                  { public:    ~PublicDestructor() {}};
~ProtectedDestructorProtectedDestructor60 struct ProtectedDestructor               { protected: ~ProtectedDestructor() {}};
~PrivateDestructorPrivateDestructor61 struct PrivateDestructor                 { private:   ~PrivateDestructor() {}};
62 
~VirtualPublicDestructorVirtualPublicDestructor63 struct VirtualPublicDestructor           { public:    virtual ~VirtualPublicDestructor() {}};
~VirtualProtectedDestructorVirtualProtectedDestructor64 struct VirtualProtectedDestructor        { protected: virtual ~VirtualProtectedDestructor() {}};
~VirtualPrivateDestructorVirtualPrivateDestructor65 struct VirtualPrivateDestructor          { private:   virtual ~VirtualPrivateDestructor() {}};
66 
67 struct PurePublicDestructor              { public:    virtual ~PurePublicDestructor() = 0; };
68 struct PureProtectedDestructor           { protected: virtual ~PureProtectedDestructor() = 0; };
69 struct PurePrivateDestructor             { private:   virtual ~PurePrivateDestructor() = 0; };
70 
71 struct DeletedPublicDestructor           { public:    ~DeletedPublicDestructor() = delete; };
72 struct DeletedProtectedDestructor        { protected: ~DeletedProtectedDestructor() = delete; };
73 struct DeletedPrivateDestructor          { private:   ~DeletedPrivateDestructor() = delete; };
74 
75 struct DeletedVirtualPublicDestructor    { public:    virtual ~DeletedVirtualPublicDestructor() = delete; };
76 struct DeletedVirtualProtectedDestructor { protected: virtual ~DeletedVirtualProtectedDestructor() = delete; };
77 struct DeletedVirtualPrivateDestructor   { private:   virtual ~DeletedVirtualPrivateDestructor() = delete; };
78 
79 
main()80 int main()
81 {
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>();
99 
100     test_is_not_destructible<int[]>();
101     test_is_not_destructible<void>();
102 
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>();
112 
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>();
116 
117 #if __has_feature(cxx_access_control_sfinae)
118     test_is_not_destructible<NotEmpty>();
119 #endif
120     test_is_not_destructible<Function>();
121 }
122