blob: 0908f8b2b426ab0acb00ced61dabad870aaf04ae [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_trivially_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
Howard Hinnant1468b662010-11-19 22:17:28 +000018template <class T>
19void 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
27template <class T>
Marshall Clowe33e03e2014-09-02 16:19:38 +000028void test_is_not_trivially_destructible()
Howard Hinnant1468b662010-11-19 22:17:28 +000029{
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
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000036struct PublicDestructor { public: ~PublicDestructor() {}};
37struct ProtectedDestructor { protected: ~ProtectedDestructor() {}};
38struct PrivateDestructor { private: ~PrivateDestructor() {}};
39
40struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}};
41struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}};
42struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}};
43
44struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; };
45struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; };
46struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; };
47
48
Howard Hinnant1468b662010-11-19 22:17:28 +000049class Empty
50{
51};
52
Howard Hinnant1468b662010-11-19 22:17:28 +000053union Union {};
54
55struct bit_zero
56{
57 int : 0;
58};
59
60class Abstract
61{
Marshall Clow2b44e3d2014-07-16 15:51:50 +000062 virtual void foo() = 0;
63};
64
65class AbstractDestructor
66{
67 virtual ~AbstractDestructor() = 0;
Howard Hinnant1468b662010-11-19 22:17:28 +000068};
69
70struct A
71{
72 ~A();
73};
74
75int main()
76{
Marshall Clowe33e03e2014-09-02 16:19:38 +000077 test_is_not_trivially_destructible<void>();
78 test_is_not_trivially_destructible<A>();
Marshall Clowe33e03e2014-09-02 16:19:38 +000079 test_is_not_trivially_destructible<char[]>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000080 test_is_not_trivially_destructible<VirtualPublicDestructor>();
81 test_is_not_trivially_destructible<PurePublicDestructor>();
Howard Hinnant1468b662010-11-19 22:17:28 +000082
Marshall Clow2b44e3d2014-07-16 15:51:50 +000083 test_is_trivially_destructible<Abstract>();
Howard Hinnant1468b662010-11-19 22:17:28 +000084 test_is_trivially_destructible<Union>();
85 test_is_trivially_destructible<Empty>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000086 test_is_trivially_destructible<int&>();
Howard Hinnant1468b662010-11-19 22:17:28 +000087 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]>();
Howard Hinnant1468b662010-11-19 22:17:28 +000092 test_is_trivially_destructible<bit_zero>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000093
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
Howard Hinnant1468b662010-11-19 22:17:28 +0000103}