git: bb6713d38cc0 - main - libcxx-compat: revert llvmorg-21-init-15984-g650b451d0065:
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 25 Apr 2026 14:20:09 UTC
The branch main has been updated by dim:
URL: https://cgit.FreeBSD.org/src/commit/?id=bb6713d38cc0d988378394f599d81d3a83dbaf03
commit bb6713d38cc0d988378394f599d81d3a83dbaf03
Author: Dimitry Andric <dimitry@andric.com>
AuthorDate: 2026-01-04 19:43:58 +0000
Commit: Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2026-04-25 14:14:20 +0000
libcxx-compat: revert llvmorg-21-init-15984-g650b451d0065:
[libc++] Simplify the implementation of pointer_traits a bit (#142260)
This is part of making libc++ 21 build with clang 18.
PR: 292067
MFC after: 1 month
---
.../libcxx/include/__memory/pointer_traits.h | 116 +++++++++++++++------
1 file changed, 83 insertions(+), 33 deletions(-)
diff --git a/contrib/llvm-project/libcxx/include/__memory/pointer_traits.h b/contrib/llvm-project/libcxx/include/__memory/pointer_traits.h
index 8c7f8dff1b76..879b387b9ad1 100644
--- a/contrib/llvm-project/libcxx/include/__memory/pointer_traits.h
+++ b/contrib/llvm-project/libcxx/include/__memory/pointer_traits.h
@@ -16,13 +16,11 @@
#include <__type_traits/conditional.h>
#include <__type_traits/conjunction.h>
#include <__type_traits/decay.h>
-#include <__type_traits/detected_or.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/integral_constant.h>
#include <__type_traits/is_class.h>
#include <__type_traits/is_function.h>
#include <__type_traits/is_void.h>
-#include <__type_traits/nat.h>
#include <__type_traits/void_t.h>
#include <__utility/declval.h>
#include <__utility/forward.h>
@@ -36,37 +34,67 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
+// clang-format off
+#define _LIBCPP_CLASS_TRAITS_HAS_XXX(NAME, PROPERTY) \
+ template <class _Tp, class = void> \
+ struct NAME : false_type {}; \
+ template <class _Tp> \
+ struct NAME<_Tp, __void_t<typename _Tp::PROPERTY> > : true_type {}
+// clang-format on
+
+_LIBCPP_CLASS_TRAITS_HAS_XXX(__has_pointer, pointer);
+_LIBCPP_CLASS_TRAITS_HAS_XXX(__has_element_type, element_type);
+
+template <class _Ptr, bool = __has_element_type<_Ptr>::value>
+struct __pointer_traits_element_type {};
+
template <class _Ptr>
-struct __pointer_traits_element_type_impl {};
+struct __pointer_traits_element_type<_Ptr, true> {
+ using type _LIBCPP_NODEBUG = typename _Ptr::element_type;
+};
template <template <class, class...> class _Sp, class _Tp, class... _Args>
-struct __pointer_traits_element_type_impl<_Sp<_Tp, _Args...> > {
+struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> {
+ using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::element_type;
+};
+
+template <template <class, class...> class _Sp, class _Tp, class... _Args>
+struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> {
using type _LIBCPP_NODEBUG = _Tp;
};
-template <class _Ptr, class = void>
-struct __pointer_traits_element_type : __pointer_traits_element_type_impl<_Ptr> {};
+template <class _Tp, class = void>
+struct __has_difference_type : false_type {};
+
+template <class _Tp>
+struct __has_difference_type<_Tp, __void_t<typename _Tp::difference_type> > : true_type {};
+
+template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
+struct __pointer_traits_difference_type {
+ using type _LIBCPP_NODEBUG = ptrdiff_t;
+};
template <class _Ptr>
-struct __pointer_traits_element_type<_Ptr, __void_t<typename _Ptr::element_type> > {
- using type _LIBCPP_NODEBUG = typename _Ptr::element_type;
+struct __pointer_traits_difference_type<_Ptr, true> {
+ using type _LIBCPP_NODEBUG = typename _Ptr::difference_type;
};
template <class _Tp, class _Up>
-struct __pointer_traits_rebind_impl {
- static_assert(false, "Cannot rebind pointer; did you forget to add a rebind member to your pointer?");
-};
+struct __has_rebind {
+private:
+ template <class _Xp>
+ static false_type __test(...);
+ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
+ template <class _Xp>
+ static true_type __test(typename _Xp::template rebind<_Up>* = 0);
+ _LIBCPP_SUPPRESS_DEPRECATED_POP
-template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up>
-struct __pointer_traits_rebind_impl<_Sp<_Tp, _Args...>, _Up> {
- using type _LIBCPP_NODEBUG = _Sp<_Up, _Args...>;
+public:
+ static const bool value = decltype(__test<_Tp>(0))::value;
};
-template <class _Tp, class _Up, class = void>
-struct __pointer_traits_rebind : __pointer_traits_rebind_impl<_Tp, _Up> {};
-
-template <class _Tp, class _Up>
-struct __pointer_traits_rebind<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up> > > {
+template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
+struct __pointer_traits_rebind {
#ifndef _LIBCPP_CXX03_LANG
using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>;
#else
@@ -74,8 +102,19 @@ struct __pointer_traits_rebind<_Tp, _Up, __void_t<typename _Tp::template rebind<
#endif
};
-template <class _Tp>
-using __difference_type_member _LIBCPP_NODEBUG = typename _Tp::difference_type;
+template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> {
+#ifndef _LIBCPP_CXX03_LANG
+ using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::template rebind<_Up>;
+#else
+ using type _LIBCPP_NODEBUG = typename _Sp<_Tp, _Args...>::template rebind<_Up>::other;
+#endif
+};
+
+template <template <class, class...> class _Sp, class _Tp, class... _Args, class _Up>
+struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false> {
+ typedef _Sp<_Up, _Args...> type;
+};
template <class _Ptr, class = void>
struct __pointer_traits_impl {};
@@ -84,7 +123,7 @@ template <class _Ptr>
struct __pointer_traits_impl<_Ptr, __void_t<typename __pointer_traits_element_type<_Ptr>::type> > {
typedef _Ptr pointer;
typedef typename __pointer_traits_element_type<pointer>::type element_type;
- using difference_type = __detected_or_t<ptrdiff_t, __difference_type_member, pointer>;
+ typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
#ifndef _LIBCPP_CXX03_LANG
template <class _Up>
@@ -96,6 +135,9 @@ struct __pointer_traits_impl<_Ptr, __void_t<typename __pointer_traits_element_ty
};
#endif // _LIBCPP_CXX03_LANG
+private:
+ struct __nat {};
+
public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
pointer_to(__conditional_t<is_void<element_type>::value, __nat, element_type>& __r) {
@@ -122,6 +164,9 @@ struct pointer_traits<_Tp*> {
};
#endif
+private:
+ struct __nat {};
+
public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static pointer
pointer_to(__conditional_t<is_void<element_type>::value, __nat, element_type>& __r) _NOEXCEPT {
@@ -212,26 +257,20 @@ template <class _Tp>
struct __pointer_of {};
template <class _Tp>
-concept __has_pointer_member = requires { typename _Tp::pointer; };
-
-template <class _Tp>
-concept __has_element_type_member = requires { typename _Tp::element_type; };
-
-template <class _Tp>
- requires __has_pointer_member<_Tp>
+ requires(__has_pointer<_Tp>::value)
struct __pointer_of<_Tp> {
using type _LIBCPP_NODEBUG = typename _Tp::pointer;
};
template <class _Tp>
- requires(!__has_pointer_member<_Tp> && __has_element_type_member<_Tp>)
+ requires(!__has_pointer<_Tp>::value && __has_element_type<_Tp>::value)
struct __pointer_of<_Tp> {
using type _LIBCPP_NODEBUG = typename _Tp::element_type*;
};
template <class _Tp>
- requires(!__has_pointer_member<_Tp> && !__has_element_type_member<_Tp> &&
- __has_element_type_member<pointer_traits<_Tp>>)
+ requires(!__has_pointer<_Tp>::value && !__has_element_type<_Tp>::value &&
+ __has_element_type<pointer_traits<_Tp>>::value)
struct __pointer_of<_Tp> {
using type _LIBCPP_NODEBUG = typename pointer_traits<_Tp>::element_type*;
};
@@ -239,8 +278,19 @@ struct __pointer_of<_Tp> {
template <typename _Tp>
using __pointer_of_t _LIBCPP_NODEBUG = typename __pointer_of<_Tp>::type;
+template <class _Tp, class _Up>
+struct __pointer_of_or {
+ using type _LIBCPP_NODEBUG = _Up;
+};
+
+template <class _Tp, class _Up>
+ requires requires { typename __pointer_of_t<_Tp>; }
+struct __pointer_of_or<_Tp, _Up> {
+ using type _LIBCPP_NODEBUG = __pointer_of_t<_Tp>;
+};
+
template <typename _Tp, typename _Up>
-using __pointer_of_or_t _LIBCPP_NODEBUG = __detected_or_t<_Up, __pointer_of_t, _Tp>;
+using __pointer_of_or_t _LIBCPP_NODEBUG = typename __pointer_of_or<_Tp, _Up>::type;
template <class _Smart>
concept __resettable_smart_pointer = requires(_Smart __s) { __s.reset(); };