* [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497]
2024-06-20 15:30 [PATCH 1/4] libstdc++: Don't use std::__is_scalar in std::valarray initialization [PR115497] Jonathan Wakely
@ 2024-06-20 15:30 ` Jonathan Wakely
2024-06-20 15:30 ` [PATCH 3/4] libstdc++: Remove std::__is_void class template [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497] Jonathan Wakely
2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-20 15:30 UTC (permalink / raw)
To: libstdc++, gcc-patches
Tested x86_64-linux.
-- >8 --
This replaces all uses of the std::__is_pointer type trait with uses of
the new __is_pointer built-in. Since the class template was only used to
enable some performance optimizations for algorithms, we can use the
built-in when __has_builtin(__is_pointer) is true (which is the case for
GCC trunk and for current versions of Clang) and just forego the
optimization otherwise.
Removing the uses of std::__is_pointer means it can be removed from
<bits/cpp_type_traits.h>, which is another step towards fixing PR
115497.
libstdc++-v3/ChangeLog:
PR libstdc++/115497
* include/bits/deque.tcc (__lex_cmp_dit): Replace __is_pointer
class template with __is_pointer(T) built-in.
(__lexicographical_compare_aux1): Likewise.
* include/bits/stl_algobase.h (__equal_aux1): Likewise.
(__lexicographical_compare_aux1): Likewise.
---
libstdc++-v3/include/bits/deque.tcc | 19 ++++++++++++-------
libstdc++-v3/include/bits/stl_algobase.h | 13 +++++++++----
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc
index 2c12358ca5b..deb010a0ebb 100644
--- a/libstdc++-v3/include/bits/deque.tcc
+++ b/libstdc++-v3/include/bits/deque.tcc
@@ -1271,18 +1271,21 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_STD_C::_Deque_iterator<_Tp1, _Ref, _Ptr> __last1,
const _Tp2* __first2, const _Tp2* __last2)
{
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
const bool __simple =
(__is_memcmp_ordered_with<_Tp1, _Tp2>::__value
- && __is_pointer<_Ptr>::__value
+ && __is_pointer(_Ptr)
#if __cplusplus > 201703L && __cpp_lib_concepts
// For C++20 iterator_traits<volatile T*>::value_type is non-volatile
// so __is_byte<T> could be true, but we can't use memcmp with
// volatile data.
- && !is_volatile_v<_Tp1>
- && !is_volatile_v<_Tp2>
+ && !is_volatile_v<_Tp1> && !is_volatile_v<_Tp2>
#endif
);
typedef std::__lexicographical_compare<__simple> _Lc;
+#else
+ typedef std::__lexicographical_compare<false> _Lc;
+#endif
while (__first1._M_node != __last1._M_node)
{
@@ -1327,19 +1330,21 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __first2,
_GLIBCXX_STD_C::_Deque_iterator<_Tp2, _Ref2, _Ptr2> __last2)
{
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
const bool __simple =
(__is_memcmp_ordered_with<_Tp1, _Tp2>::__value
- && __is_pointer<_Ptr1>::__value
- && __is_pointer<_Ptr2>::__value
+ && __is_pointer(_Ptr1) && __is_pointer(_Ptr2)
#if __cplusplus > 201703L && __cpp_lib_concepts
// For C++20 iterator_traits<volatile T*>::value_type is non-volatile
// so __is_byte<T> could be true, but we can't use memcmp with
// volatile data.
- && !is_volatile_v<_Tp1>
- && !is_volatile_v<_Tp2>
+ && !is_volatile_v<_Tp1> && !is_volatile_v<_Tp2>
#endif
);
typedef std::__lexicographical_compare<__simple> _Lc;
+#else
+ typedef std::__lexicographical_compare<false> _Lc;
+#endif
while (__first1 != __last1)
{
diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index 1a0f8c14073..57ff2f7cb08 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -1256,8 +1256,10 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
{
typedef typename iterator_traits<_II1>::value_type _ValueType1;
const bool __simple = ((__is_integer<_ValueType1>::__value
- || __is_pointer<_ValueType1>::__value)
- && __memcmpable<_II1, _II2>::__value);
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
+ || __is_pointer(_ValueType1)
+#endif
+ ) && __memcmpable<_II1, _II2>::__value);
return std::__equal<__simple>::equal(__first1, __last1, __first2);
}
@@ -1420,10 +1422,10 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
{
typedef typename iterator_traits<_II1>::value_type _ValueType1;
typedef typename iterator_traits<_II2>::value_type _ValueType2;
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
const bool __simple =
(__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value
- && __is_pointer<_II1>::__value
- && __is_pointer<_II2>::__value
+ && __is_pointer(_II1) && __is_pointer(_II2)
#if __cplusplus > 201703L && __glibcxx_concepts
// For C++20 iterator_traits<volatile T*>::value_type is non-volatile
// so __is_byte<T> could be true, but we can't use memcmp with
@@ -1432,6 +1434,9 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
&& !is_volatile_v<remove_reference_t<iter_reference_t<_II2>>>
#endif
);
+#else
+ const bool __simple = false;
+#endif
return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
__first2, __last2);
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] libstdc++: Remove std::__is_void class template [PR115497]
2024-06-20 15:30 [PATCH 1/4] libstdc++: Don't use std::__is_scalar in std::valarray initialization [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497] Jonathan Wakely
@ 2024-06-20 15:30 ` Jonathan Wakely
2024-06-20 15:30 ` [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497] Jonathan Wakely
2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-20 15:30 UTC (permalink / raw)
To: libstdc++, gcc-patches
Tested x86_64-linux.
-- >8 --
This removes the std::__is_void trait, as it conflicts with a Clang
built-in. There is only one use of the trait, which can easily be
replaced by simpler code.
Although Clang has a hack to make the class template work despite using
a reserved name, removing std::__is_void will allow that hack to be
dropped at some future date.
libstdc++-v3/ChangeLog:
PR libstdc++/115497
* include/bits/cpp_type_traits.h (__is_void): Remove.
* include/debug/helper_functions.h (_Distance_traits):
Adjust partial specialization to match void directly, instead of
using __is_void<T>::__type and matching __true_type.
---
libstdc++-v3/include/bits/cpp_type_traits.h | 15 ---------------
libstdc++-v3/include/debug/helper_functions.h | 5 ++---
2 files changed, 2 insertions(+), 18 deletions(-)
diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index 6834dee5557..4d83b9472e6 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -105,21 +105,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef __true_type __type;
};
- // Holds if the template-argument is a void type.
- template<typename _Tp>
- struct __is_void
- {
- enum { __value = 0 };
- typedef __false_type __type;
- };
-
- template<>
- struct __is_void<void>
- {
- enum { __value = 1 };
- typedef __true_type __type;
- };
-
//
// Integer types
//
diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h
index 5474399dc67..d686a29e8ee 100644
--- a/libstdc++-v3/include/debug/helper_functions.h
+++ b/libstdc++-v3/include/debug/helper_functions.h
@@ -66,13 +66,12 @@ namespace __gnu_debug
typedef
typename std::iterator_traits<_Iterator>::difference_type _ItDiffType;
- template<typename _DiffType,
- typename = typename std::__is_void<_DiffType>::__type>
+ template<typename _DiffType, typename = _DiffType> // PR c++/85282
struct _DiffTraits
{ typedef _DiffType __type; };
template<typename _DiffType>
- struct _DiffTraits<_DiffType, std::__true_type>
+ struct _DiffTraits<_DiffType, void>
{ typedef std::ptrdiff_t __type; };
typedef typename _DiffTraits<_ItDiffType>::__type _DiffType;
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] libstdc++: Remove std::__is_pointer and std::__is_scalar [PR115497]
2024-06-20 15:30 [PATCH 1/4] libstdc++: Don't use std::__is_scalar in std::valarray initialization [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 2/4] libstdc++: Stop using std::__is_pointer in <deque> and <algorithm> [PR115497] Jonathan Wakely
2024-06-20 15:30 ` [PATCH 3/4] libstdc++: Remove std::__is_void class template [PR115497] Jonathan Wakely
@ 2024-06-20 15:30 ` Jonathan Wakely
2024-06-21 9:31 ` Jonathan Wakely
2 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2024-06-20 15:30 UTC (permalink / raw)
To: libstdc++, gcc-patches
We still have __is_arithmetic in <bits/cpp_type_traits.h> after this,
but that needs a lot more work to remove its uses from <cmath> and
<tr1/cmath>.
Tested x86_64-linux.
-- >8 --
This removes the std::__is_pointer and std::__is_scalar traits, as they
conflicts with a Clang built-in.
Although Clang has a hack to make the class templates work despite using
reserved names, removing these class templates will allow that hack to
be dropped at some future date.
libstdc++-v3/ChangeLog:
PR libstdc++/115497
* include/bits/cpp_type_traits.h (__is_pointer, __is_scalar):
Remove.
(__is_arithmetic): Do not use __is_pointer in the primary
template. Add partial specialization for pointers.
---
libstdc++-v3/include/bits/cpp_type_traits.h | 33 ---------------------
1 file changed, 33 deletions(-)
diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index 4d83b9472e6..abe0c7603e3 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -343,31 +343,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
};
#endif
- //
- // Pointer types
- //
-#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_pointer)
- template<typename _Tp, bool _IsPtr = __is_pointer(_Tp)>
- struct __is_pointer : __truth_type<_IsPtr>
- {
- enum { __value = _IsPtr };
- };
-#else
- template<typename _Tp>
- struct __is_pointer
- {
- enum { __value = 0 };
- typedef __false_type __type;
- };
-
- template<typename _Tp>
- struct __is_pointer<_Tp*>
- {
- enum { __value = 1 };
- typedef __true_type __type;
- };
-#endif
-
//
// An arithmetic type is an integer type or a floating point type
//
@@ -376,14 +351,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
: public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
{ };
- //
- // A scalar type is an arithmetic type or a pointer type
- //
- template<typename _Tp>
- struct __is_scalar
- : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> >
- { };
-
//
// For use in std::copy and std::find overloads for streambuf iterators.
//
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread