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_trivially_destructible
13 
14 #include <type_traits>
15 
16 #include "test_macros.h"
17 
18 template <class T>
test_is_trivially_destructible()19 void test_is_trivially_destructible()
20 {
21     static_assert( std::is_trivially_destructible<T>::value, "");
22     static_assert( std::is_trivially_destructible<const T>::value, "");
23     static_assert( std::is_trivially_destructible<volatile T>::value, "");
24     static_assert( std::is_trivially_destructible<const volatile T>::value, "");
25 }
26 
27 template <class T>
test_is_not_trivially_destructible()28 void test_is_not_trivially_destructible()
29 {
30     static_assert(!std::is_trivially_destructible<T>::value, "");
31     static_assert(!std::is_trivially_destructible<const T>::value, "");
32     static_assert(!std::is_trivially_destructible<volatile T>::value, "");
33     static_assert(!std::is_trivially_destructible<const volatile T>::value, "");
34 }
35 
~PublicDestructorPublicDestructor36 struct PublicDestructor           { public:     ~PublicDestructor() {}};
~ProtectedDestructorProtectedDestructor37 struct ProtectedDestructor        { protected:  ~ProtectedDestructor() {}};
~PrivateDestructorPrivateDestructor38 struct PrivateDestructor          { private:    ~PrivateDestructor() {}};
39 
~VirtualPublicDestructorVirtualPublicDestructor40 struct VirtualPublicDestructor           { public:    virtual ~VirtualPublicDestructor() {}};
~VirtualProtectedDestructorVirtualProtectedDestructor41 struct VirtualProtectedDestructor        { protected: virtual ~VirtualProtectedDestructor() {}};
~VirtualPrivateDestructorVirtualPrivateDestructor42 struct VirtualPrivateDestructor          { private:   virtual ~VirtualPrivateDestructor() {}};
43 
44 struct PurePublicDestructor              { public:    virtual ~PurePublicDestructor() = 0; };
45 struct PureProtectedDestructor           { protected: virtual ~PureProtectedDestructor() = 0; };
46 struct PurePrivateDestructor             { private:   virtual ~PurePrivateDestructor() = 0; };
47 
48 
49 class Empty
50 {
51 };
52 
53 union Union {};
54 
55 struct bit_zero
56 {
57     int :  0;
58 };
59 
60 class Abstract
61 {
62     virtual void foo() = 0;
63 };
64 
65 class AbstractDestructor
66 {
67     virtual ~AbstractDestructor() = 0;
68 };
69 
70 struct A
71 {
72     ~A();
73 };
74 
main()75 int main()
76 {
77     test_is_not_trivially_destructible<void>();
78     test_is_not_trivially_destructible<A>();
79     test_is_not_trivially_destructible<char[]>();
80     test_is_not_trivially_destructible<VirtualPublicDestructor>();
81     test_is_not_trivially_destructible<PurePublicDestructor>();
82 
83     test_is_trivially_destructible<Abstract>();
84     test_is_trivially_destructible<Union>();
85     test_is_trivially_destructible<Empty>();
86     test_is_trivially_destructible<int&>();
87     test_is_trivially_destructible<int>();
88     test_is_trivially_destructible<double>();
89     test_is_trivially_destructible<int*>();
90     test_is_trivially_destructible<const int*>();
91     test_is_trivially_destructible<char[3]>();
92     test_is_trivially_destructible<bit_zero>();
93 
94 #if TEST_STD_VER >= 11
95     // requires access control sfinae
96     test_is_not_trivially_destructible<ProtectedDestructor>();
97     test_is_not_trivially_destructible<PrivateDestructor>();
98     test_is_not_trivially_destructible<VirtualProtectedDestructor>();
99     test_is_not_trivially_destructible<VirtualPrivateDestructor>();
100     test_is_not_trivially_destructible<PureProtectedDestructor>();
101     test_is_not_trivially_destructible<PurePrivateDestructor>();
102 #endif
103 }
104