Skip to content

Commit 4013f32

Browse files
committed
Revert "[libc++] Remove dead implementation of is_nothrow_convertible and merge the remaining code into is_convertible.h (llvm#137717)"
This reverts commit e43e8ec.
1 parent 5d5f0bd commit 4013f32

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-10
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ set(files
847847
__type_traits/is_member_pointer.h
848848
__type_traits/is_nothrow_assignable.h
849849
__type_traits/is_nothrow_constructible.h
850+
__type_traits/is_nothrow_convertible.h
850851
__type_traits/is_nothrow_destructible.h
851852
__type_traits/is_null_pointer.h
852853
__type_traits/is_object.h

libcxx/include/__type_traits/is_convertible.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ template <class _From, class _To>
2626
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_convertible_v = __is_convertible(_From, _To);
2727
#endif
2828

29-
#if _LIBCPP_STD_VER >= 20
30-
31-
template <class _Tp, class _Up>
32-
struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
33-
34-
template <class _Tp, class _Up>
35-
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
36-
37-
#endif // _LIBCPP_STD_VER >= 20
38-
3929
_LIBCPP_END_NAMESPACE_STD
4030

4131
#endif // _LIBCPP___TYPE_TRAITS_IS_CONVERTIBLE_H
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
#ifndef _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
10+
#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H
11+
12+
#include <__config>
13+
#include <__type_traits/conjunction.h>
14+
#include <__type_traits/disjunction.h>
15+
#include <__type_traits/integral_constant.h>
16+
#include <__type_traits/is_convertible.h>
17+
#include <__type_traits/is_void.h>
18+
#include <__type_traits/lazy.h>
19+
#include <__utility/declval.h>
20+
21+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22+
# pragma GCC system_header
23+
#endif
24+
25+
_LIBCPP_BEGIN_NAMESPACE_STD
26+
27+
#if _LIBCPP_STD_VER >= 20
28+
29+
# if __has_builtin(__is_nothrow_convertible)
30+
31+
template <class _Tp, class _Up>
32+
struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
33+
34+
template <class _Tp, class _Up>
35+
_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_convertible_v = __is_nothrow_convertible(_Tp, _Up);
36+
37+
# else // __has_builtin(__is_nothrow_convertible)
38+
39+
template <typename _Tp>
40+
void __test_noexcept(_Tp) noexcept;
41+
42+
template <typename _Fm, typename _To>
43+
bool_constant<noexcept(std::__test_noexcept<_To>(std::declval<_Fm>()))> __is_nothrow_convertible_test();
44+
45+
template <typename _Fm, typename _To>
46+
struct __is_nothrow_convertible_helper : decltype(std::__is_nothrow_convertible_test<_Fm, _To>()) {};
47+
48+
template <typename _Fm, typename _To>
49+
struct is_nothrow_convertible
50+
: _Or<_And<is_void<_To>, is_void<_Fm>>,
51+
_Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To> > >::type {};
52+
53+
template <typename _Fm, typename _To>
54+
inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
55+
56+
# endif // __has_builtin(__is_nothrow_convertible)
57+
58+
#endif // _LIBCPP_STD_VER >= 20
59+
60+
_LIBCPP_END_NAMESPACE_STD
61+
62+
#endif // _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONVERTIBLE_H

libcxx/include/module.modulemap.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ module std_core [system] {
232232
header "__type_traits/is_nothrow_constructible.h"
233233
export std_core.type_traits.integral_constant
234234
}
235+
module is_nothrow_convertible {
236+
header "__type_traits/is_nothrow_convertible.h"
237+
export std_core.type_traits.integral_constant
238+
}
235239
module is_nothrow_destructible {
236240
header "__type_traits/is_nothrow_destructible.h"
237241
export std_core.type_traits.integral_constant

libcxx/include/type_traits

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ namespace std
548548
# include <__type_traits/common_reference.h>
549549
# include <__type_traits/is_bounded_array.h>
550550
# include <__type_traits/is_constant_evaluated.h>
551+
# include <__type_traits/is_nothrow_convertible.h>
551552
# include <__type_traits/is_unbounded_array.h>
552553
# include <__type_traits/type_identity.h>
553554
# include <__type_traits/unwrap_ref.h>

0 commit comments

Comments
 (0)