blob: 5827c927f11f5dacfa52bba352198baa7b8d7c93 [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_nothrow_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_nothrow_destructible()
20{
21 static_assert( std::is_nothrow_destructible<T>::value, "");
22 static_assert( std::is_nothrow_destructible<const T>::value, "");
23 static_assert( std::is_nothrow_destructible<volatile T>::value, "");
24 static_assert( std::is_nothrow_destructible<const volatile T>::value, "");
25}
26
27template <class T>
Marshall Clowe33e03e2014-09-02 16:19:38 +000028void test_is_not_nothrow_destructible()
Howard Hinnant1468b662010-11-19 22:17:28 +000029{
30 static_assert(!std::is_nothrow_destructible<T>::value, "");
31 static_assert(!std::is_nothrow_destructible<const T>::value, "");
32 static_assert(!std::is_nothrow_destructible<volatile T>::value, "");
33 static_assert(!std::is_nothrow_destructible<const volatile T>::value, "");
34}
35
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000036
37struct PublicDestructor { public: ~PublicDestructor() {}};
38struct ProtectedDestructor { protected: ~ProtectedDestructor() {}};
39struct PrivateDestructor { private: ~PrivateDestructor() {}};
40
41struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}};
42struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}};
43struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}};
44
45struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; };
46struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; };
47struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; };
48
Howard Hinnant1468b662010-11-19 22:17:28 +000049class Empty
50{
51};
52
Howard Hinnant1468b662010-11-19 22:17:28 +000053
54union Union {};
55
56struct bit_zero
57{
58 int : 0;
59};
60
61class Abstract
62{
Marshall Clow2b44e3d2014-07-16 15:51:50 +000063 virtual void foo() = 0;
64};
65
Howard Hinnant1468b662010-11-19 22:17:28 +000066
67int main()
68{
Marshall Clowe33e03e2014-09-02 16:19:38 +000069 test_is_not_nothrow_destructible<void>();
Marshall Clowe33e03e2014-09-02 16:19:38 +000070 test_is_not_nothrow_destructible<char[]>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000071 test_is_not_nothrow_destructible<char[][3]>();
Howard Hinnant1468b662010-11-19 22:17:28 +000072
Howard Hinnant1468b662010-11-19 22:17:28 +000073 test_is_nothrow_destructible<int&>();
Howard Hinnant1468b662010-11-19 22:17:28 +000074 test_is_nothrow_destructible<int>();
75 test_is_nothrow_destructible<double>();
76 test_is_nothrow_destructible<int*>();
77 test_is_nothrow_destructible<const int*>();
78 test_is_nothrow_destructible<char[3]>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000079
80#if TEST_STD_VER >= 11
81 // requires noexcept. These are all destructible.
82 test_is_nothrow_destructible<PublicDestructor>();
83 test_is_nothrow_destructible<VirtualPublicDestructor>();
84 test_is_nothrow_destructible<PurePublicDestructor>();
Howard Hinnant1468b662010-11-19 22:17:28 +000085 test_is_nothrow_destructible<bit_zero>();
Eric Fiselier12c6d9c2015-07-18 16:43:58 +000086 test_is_nothrow_destructible<Abstract>();
87 test_is_nothrow_destructible<Empty>();
88 test_is_nothrow_destructible<Union>();
89
90 // requires access control
91 test_is_not_nothrow_destructible<ProtectedDestructor>();
92 test_is_not_nothrow_destructible<PrivateDestructor>();
93 test_is_not_nothrow_destructible<VirtualProtectedDestructor>();
94 test_is_not_nothrow_destructible<VirtualPrivateDestructor>();
95 test_is_not_nothrow_destructible<PureProtectedDestructor>();
96 test_is_not_nothrow_destructible<PurePrivateDestructor>();
Marshall Clow933afa92013-07-04 00:10:01 +000097#endif
Howard Hinnant1468b662010-11-19 22:17:28 +000098}