Skip to content

Commit 16d02cd

Browse files
authored
[libc++] Use __is_nothrow_destructible (#95766)
This changes the behaviour in C++03 mode because we'll now use the builtin on Clang, but I don't think that's much of a problem.
1 parent f9795f3 commit 16d02cd

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

libcxx/include/__type_traits/is_nothrow_destructible.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#include <__config>
1313
#include <__type_traits/integral_constant.h>
1414
#include <__type_traits/is_destructible.h>
15-
#include <__type_traits/is_reference.h>
16-
#include <__type_traits/is_scalar.h>
17-
#include <__type_traits/remove_all_extents.h>
1815
#include <__utility/declval.h>
1916
#include <cstddef>
2017

@@ -24,7 +21,12 @@
2421

2522
_LIBCPP_BEGIN_NAMESPACE_STD
2623

27-
#if !defined(_LIBCPP_CXX03_LANG)
24+
#if __has_builtin(__is_nothrow_destructible)
25+
26+
template <class _Tp>
27+
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible : integral_constant<bool, __is_nothrow_destructible(_Tp)> {};
28+
29+
#else
2830

2931
template <bool, class _Tp>
3032
struct __libcpp_is_nothrow_destructible;
@@ -49,20 +51,7 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&> : public true_type {};
4951
template <class _Tp>
5052
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&> : public true_type {};
5153

52-
#else
53-
54-
template <class _Tp>
55-
struct __libcpp_nothrow_destructor : public integral_constant<bool, is_scalar<_Tp>::value || is_reference<_Tp>::value> {
56-
};
57-
58-
template <class _Tp>
59-
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible : public __libcpp_nothrow_destructor<__remove_all_extents_t<_Tp> > {
60-
};
61-
62-
template <class _Tp>
63-
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]> : public false_type {};
64-
65-
#endif
54+
#endif // __has_builtin(__is_nothrow_destructible)
6655

6756
#if _LIBCPP_STD_VER >= 17
6857
template <class _Tp>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ struct PurePublicDestructor { public: virtual ~PurePublicDestruc
5656
struct PureProtectedDestructor { protected: virtual ~PureProtectedDestructor() = 0; };
5757
struct PurePrivateDestructor { private: virtual ~PurePrivateDestructor() = 0; };
5858

59+
struct ExplicitlyNoThrowDestructor {
60+
~ExplicitlyNoThrowDestructor() TEST_NOEXCEPT {}
61+
};
62+
5963
class Empty
6064
{
6165
};
@@ -92,11 +96,12 @@ int main(int, char**)
9296
test_is_nothrow_destructible<PublicDestructor>();
9397
test_is_nothrow_destructible<VirtualPublicDestructor>();
9498
test_is_nothrow_destructible<PurePublicDestructor>();
99+
#endif
100+
test_is_nothrow_destructible<ExplicitlyNoThrowDestructor>();
95101
test_is_nothrow_destructible<bit_zero>();
96102
test_is_nothrow_destructible<Abstract>();
97103
test_is_nothrow_destructible<Empty>();
98104
test_is_nothrow_destructible<Union>();
99-
#endif
100105
// requires access control
101106
test_is_not_nothrow_destructible<ProtectedDestructor>();
102107
test_is_not_nothrow_destructible<PrivateDestructor>();

0 commit comments

Comments
 (0)