aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/patches/45-type-traits.patch
blob: 3a28d36a246dcc9060fab26a3640c14c89f216ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
diff --git a/include/__type_traits/enable_if.h b/include/__type_traits/enable_if.h
index 77da962..c1d8896 100644
--- a/include/__type_traits/enable_if.h
+++ b/include/__type_traits/enable_if.h
@@ -32,6 +32,12 @@ template <bool _Bp, class _Tp = void>
 using enable_if_t = typename enable_if<_Bp, _Tp>::type;
 #endif
 
+// CUDA headers use libc++ internals.
+#ifdef __CUDACC__
+template <bool _Cond, class _Ret = void>
+using __lazy_enable_if _LIBCPP_NODEBUG = __enable_if_t<_Cond, _Ret>;
+#endif
+
 _LIBCPP_END_NAMESPACE_STD
 
 #endif // _LIBCPP___TYPE_TRAITS_ENABLE_IF_H
diff --git a/include/__type_traits/is_constant_evaluated.h b/include/__type_traits/is_constant_evaluated.h
index 05e070a..7907c1f 100644
--- a/include/__type_traits/is_constant_evaluated.h
+++ b/include/__type_traits/is_constant_evaluated.h
@@ -17,15 +17,19 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER >= 20
+#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
+#  if _LIBCPP_STD_VER >= 20
 _LIBCPP_HIDE_FROM_ABI inline constexpr bool is_constant_evaluated() noexcept {
   return __builtin_is_constant_evaluated();
 }
-#endif
+#  endif
 
 _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR bool __libcpp_is_constant_evaluated() _NOEXCEPT {
   return __builtin_is_constant_evaluated();
 }
+#else
+inline _LIBCPP_CONSTEXPR bool __libcpp_is_constant_evaluated() _NOEXCEPT { return false; }
+#endif // !_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/include/__type_traits/is_nothrow_constructible.h b/include/__type_traits/is_nothrow_constructible.h
index 2f7ed84..678debb 100644
--- a/include/__type_traits/is_nothrow_constructible.h
+++ b/include/__type_traits/is_nothrow_constructible.h
@@ -25,7 +25,7 @@
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 // GCC is disabled due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106611
-#if __has_builtin(__is_nothrow_constructible) && !defined(_LIBCPP_COMPILER_GCC)
+#if __has_builtin(__is_nothrow_constructible) && !defined(_LIBCPP_COMPILER_GCC) && !defined(__CUDACC__)
 
 template < class _Tp, class... _Args>
 struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
diff --git a/include/__type_traits/is_reference.h b/include/__type_traits/is_reference.h
index 42853d4..9d85646 100644
--- a/include/__type_traits/is_reference.h
+++ b/include/__type_traits/is_reference.h
@@ -18,7 +18,8 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __has_builtin(__is_lvalue_reference) && __has_builtin(__is_rvalue_reference) && __has_builtin(__is_reference)
+#if __has_builtin(__is_lvalue_reference) && __has_builtin(__is_rvalue_reference) && __has_builtin(__is_reference) &&   \
+    !defined(__CUDACC__)
 
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : _BoolConstant<__is_lvalue_reference(_Tp)> {};
diff --git a/include/__type_traits/is_same.h b/include/__type_traits/is_same.h
index 9561b7b..5013724 100644
--- a/include/__type_traits/is_same.h
+++ b/include/__type_traits/is_same.h
@@ -18,14 +18,29 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#if __has_keyword(__is_same) && !defined(__CUDACC__)
+
 template <class _Tp, class _Up>
 struct _LIBCPP_TEMPLATE_VIS is_same : _BoolConstant<__is_same(_Tp, _Up)> {};
 
-#if _LIBCPP_STD_VER >= 17
+#  if _LIBCPP_STD_VER >= 17
 template <class _Tp, class _Up>
 inline constexpr bool is_same_v = __is_same(_Tp, _Up);
-#endif
+#  endif
+
+#else
+
+template <class _Tp, class _Up>
+struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {};
+template <class _Tp>
+struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {};
 
+#  if _LIBCPP_STD_VER > 14
+template <class _Tp, class _Up>
+inline constexpr bool is_same_v = is_same<_Tp, _Up>::value;
+#  endif
+
+#endif // __is_same
 // _IsSame<T,U> has the same effect as is_same<T,U> but instantiates fewer types:
 // is_same<A,B> and is_same<C,D> are guaranteed to be different types, but
 // _IsSame<A,B> and _IsSame<C,D> are the same type (namely, false_type).
@@ -34,10 +49,22 @@ inline constexpr bool is_same_v = __is_same(_Tp, _Up);
 // (such as in a dependent return type).
 
 template <class _Tp, class _Up>
-using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
+using _IsSame = _BoolConstant<
+#if defined(__clang__) && !defined(__CUDACC__)
+    __is_same(_Tp, _Up)
+#else
+    is_same<_Tp, _Up>::value
+#endif
+    >;
 
 template <class _Tp, class _Up>
-using _IsNotSame = _BoolConstant<!__is_same(_Tp, _Up)>;
+using _IsNotSame = _BoolConstant<
+#if defined(__clang__) && !defined(__CUDACC__)
+    !__is_same(_Tp, _Up)
+#else
+    !is_same<_Tp, _Up>::value
+#endif
+    >;
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/include/__type_traits/remove_cv.h b/include/__type_traits/remove_cv.h
index 2c4e9e4..639a9c4 100644
--- a/include/__type_traits/remove_cv.h
+++ b/include/__type_traits/remove_cv.h
@@ -10,6 +10,8 @@
 #define _LIBCPP___TYPE_TRAITS_REMOVE_CV_H
 
 #include <__config>
+#include <__type_traits/remove_const.h>
+#include <__type_traits/remove_volatile.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -19,10 +21,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 template <class _Tp>
 struct remove_cv {
+#if __has_builtin(__remove_cv)
   using type _LIBCPP_NODEBUG = __remove_cv(_Tp);
+#else
+  typedef __remove_volatile_t<__remove_const_t<_Tp> > type;
+#endif
 };
 
-#if defined(_LIBCPP_COMPILER_GCC)
+#if defined(_LIBCPP_COMPILER_GCC) || !__has_builtin(__remove_cv)
 template <class _Tp>
 using __remove_cv_t = typename remove_cv<_Tp>::type;
 #else
diff --git a/include/__type_traits/remove_cvref.h b/include/__type_traits/remove_cvref.h
index 55f894d..0334771 100644
--- a/include/__type_traits/remove_cvref.h
+++ b/include/__type_traits/remove_cvref.h
@@ -28,6 +28,10 @@ struct __remove_cvref_gcc {
 
 template <class _Tp>
 using __remove_cvref_t _LIBCPP_NODEBUG = typename __remove_cvref_gcc<_Tp>::type;
+// compatibility with cuda && clang14
+#elif defined(__CUDACC__) || !__has_builtin(__remove_cvref)
+template <class _Tp>
+using __remove_cvref_t _LIBCPP_NODEBUG = __remove_cv_t<__libcpp_remove_reference_t<_Tp> >;
 #else
 template <class _Tp>
 using __remove_cvref_t _LIBCPP_NODEBUG = __remove_cvref(_Tp);
@@ -39,7 +43,11 @@ using __is_same_uncvref = _IsSame<__remove_cvref_t<_Tp>, __remove_cvref_t<_Up> >
 #if _LIBCPP_STD_VER >= 20
 template <class _Tp>
 struct remove_cvref {
+#if defined(__CUDACC__) || !__has_builtin(__remove_cvref)
+  using type _LIBCPP_NODEBUG = __remove_cvref_t<_Tp>;
+#else
   using type _LIBCPP_NODEBUG = __remove_cvref(_Tp);
+#endif
 };
 
 template <class _Tp>