1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// type_traits
10
11// is_nothrow_destructible
12
13#include <type_traits>
14#include "test_macros.h"
15
16template <class T>
17void test_is_nothrow_destructible()
18{
19 static_assert( std::is_nothrow_destructible<T>::value, "");
20 static_assert( std::is_nothrow_destructible<const T>::value, "");
21 static_assert( std::is_nothrow_destructible<volatile T>::value, "");
22 static_assert( std::is_nothrow_destructible<const volatile T>::value, "");
23#if TEST_STD_VER > 14
24 static_assert( std::is_nothrow_destructible_v<T>, "");
25 static_assert( std::is_nothrow_destructible_v<const T>, "");
26 static_assert( std::is_nothrow_destructible_v<volatile T>, "");
27 static_assert( std::is_nothrow_destructible_v<const volatile T>, "");
28#endif
29}
30
31template <class T>
32void test_is_not_nothrow_destructible()
33{
34 static_assert(!std::is_nothrow_destructible<T>::value, "");
35 static_assert(!std::is_nothrow_destructible<const T>::value, "");
36 static_assert(!std::is_nothrow_destructible<volatile T>::value, "");
37 static_assert(!std::is_nothrow_destructible<const volatile T>::value, "");
38#if TEST_STD_VER > 14
39 static_assert(!std::is_nothrow_destructible_v<T>, "");
40 static_assert(!std::is_nothrow_destructible_v<const T>, "");
41 static_assert(!std::is_nothrow_destructible_v<volatile T>, "");
42 static_assert(!std::is_nothrow_destructible_v<const volatile T>, "");
43#endif
44}
45
46
47struct PublicDestructor { public: ~PublicDestructor() {}};
48struct ProtectedDestructor { protected: ~ProtectedDestructor() {}};
49struct PrivateDestructor { private: ~PrivateDestructor() {}};
50
51struct VirtualPublicDestructor { public: virtual ~VirtualPublicDestructor() {}};
52struct VirtualProtectedDestructor { protected: virtual ~VirtualProtectedDestructor() {}};
53struct VirtualPrivateDestructor { private: virtual ~VirtualPrivateDestructor() {}};
54
55struct PurePublicDestructor { public: virtual ~PurePublicDestructor() = 0; };
56struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; };
57struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; };
58
59class Empty
60{
61};
62
63
64union Union {};
65
66struct bit_zero
67{
68 int : 0;
69};
70
71class Abstract
72{
73 virtual void foo() = 0;
74};
75
76
77int main(int, char**)
78{
79 test_is_not_nothrow_destructible<void>();
80 test_is_not_nothrow_destructible<char[]>();
81 test_is_not_nothrow_destructible<char[][3]>();
82
83 test_is_nothrow_destructible<int&>();
84 test_is_nothrow_destructible<int>();
85 test_is_nothrow_destructible<double>();
86 test_is_nothrow_destructible<int*>();
87 test_is_nothrow_destructible<const int*>();
88 test_is_nothrow_destructible<char[3]>();
89
90#if TEST_STD_VER >= 11
91 // requires noexcept. These are all destructible.
92 test_is_nothrow_destructible<PublicDestructor>();
93 test_is_nothrow_destructible<VirtualPublicDestructor>();
94 test_is_nothrow_destructible<PurePublicDestructor>();
95 test_is_nothrow_destructible<bit_zero>();
96 test_is_nothrow_destructible<Abstract>();
97 test_is_nothrow_destructible<Empty>();
98 test_is_nothrow_destructible<Union>();
99#endif
100 // requires access control
101 test_is_not_nothrow_destructible<ProtectedDestructor>();
102 test_is_not_nothrow_destructible<PrivateDestructor>();
103 test_is_not_nothrow_destructible<VirtualProtectedDestructor>();
104 test_is_not_nothrow_destructible<VirtualPrivateDestructor>();
105 test_is_not_nothrow_destructible<PureProtectedDestructor>();
106 test_is_not_nothrow_destructible<PurePrivateDestructor>();
107
108
109 return 0;
110}
111

source code of libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp