• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "test_macros.h"
17 
18 template <class T>
test_is_destructible()19 void test_is_destructible()
20 {
21     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 
27 template <class T>
test_is_not_destructible()28 void 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, "");
34 }
35 
36 class Empty {};
37 
38 class NotEmpty
39 {
40     virtual ~NotEmpty();
41 };
42 
43 union Union {};
44 
45 struct bit_zero
46 {
47     int :  0;
48 };
49 
50 struct A
51 {
52     ~A();
53 };
54 
55 typedef void (Function) ();
56 
57 struct PublicAbstract                    { public:    virtual void foo() = 0; };
58 struct ProtectedAbstract                 { protected: virtual void foo() = 0; };
59 struct PrivateAbstract                   { private:   virtual void foo() = 0; };
60 
~PublicDestructorPublicDestructor61 struct PublicDestructor                  { public:    ~PublicDestructor() {}};
~ProtectedDestructorProtectedDestructor62 struct ProtectedDestructor               { protected: ~ProtectedDestructor() {}};
~PrivateDestructorPrivateDestructor63 struct PrivateDestructor                 { private:   ~PrivateDestructor() {}};
64 
~VirtualPublicDestructorVirtualPublicDestructor65 struct VirtualPublicDestructor           { public:    virtual ~VirtualPublicDestructor() {}};
~VirtualProtectedDestructorVirtualProtectedDestructor66 struct VirtualProtectedDestructor        { protected: virtual ~VirtualProtectedDestructor() {}};
~VirtualPrivateDestructorVirtualPrivateDestructor67 struct VirtualPrivateDestructor          { private:   virtual ~VirtualPrivateDestructor() {}};
68 
69 struct PurePublicDestructor              { public:    virtual ~PurePublicDestructor() = 0; };
70 struct PureProtectedDestructor           { protected: virtual ~PureProtectedDestructor() = 0; };
71 struct PurePrivateDestructor             { private:   virtual ~PurePrivateDestructor() = 0; };
72 
73 #if TEST_STD_VER >= 11
74 struct DeletedPublicDestructor           { public:    ~DeletedPublicDestructor() = delete; };
75 struct DeletedProtectedDestructor        { protected: ~DeletedProtectedDestructor() = delete; };
76 struct DeletedPrivateDestructor          { private:   ~DeletedPrivateDestructor() = delete; };
77 
78 struct DeletedVirtualPublicDestructor    { public:    virtual ~DeletedVirtualPublicDestructor() = delete; };
79 struct DeletedVirtualProtectedDestructor { protected: virtual ~DeletedVirtualProtectedDestructor() = delete; };
80 struct DeletedVirtualPrivateDestructor   { private:   virtual ~DeletedVirtualPrivateDestructor() = delete; };
81 #endif
82 
83 
main()84 int main()
85 {
86     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>();
96     test_is_destructible<int[3]>();
97     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>();
103 
104     test_is_not_destructible<int[]>();
105     test_is_not_destructible<void>();
106     test_is_not_destructible<Function>();
107 
108 #if TEST_STD_VER >= 11
109     // Test access controlled destructors
110     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>();
116 
117     // Test deleted constructors
118     test_is_not_destructible<DeletedPublicDestructor>();
119     test_is_not_destructible<DeletedProtectedDestructor>();
120     test_is_not_destructible<DeletedPrivateDestructor>();
121     //test_is_not_destructible<DeletedVirtualPublicDestructor>(); // previously failed due to clang bug #20268
122     test_is_not_destructible<DeletedVirtualProtectedDestructor>();
123     test_is_not_destructible<DeletedVirtualPrivateDestructor>();
124 
125     // Test private destructors
126     test_is_not_destructible<NotEmpty>();
127 #endif
128 
129 }
130