From 544f610d5310e1c1e7dd7a081d5a2a2607225740 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Thu, 8 Feb 2024 19:22:16 +0100 Subject: [PATCH] [libc++] Use __is_pointer_in_range inside vector::insert (#80624) --- libcxx/include/vector | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libcxx/include/vector b/libcxx/include/vector index 3934361e98cf6..ce7df7a9f0420 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -351,6 +351,7 @@ template requires is-vector-bool-reference // Since C++ #include <__type_traits/type_identity.h> #include <__utility/exception_guard.h> #include <__utility/forward.h> +#include <__utility/is_pointer_in_range.h> #include <__utility/move.h> #include <__utility/pair.h> #include <__utility/swap.h> @@ -1580,14 +1581,13 @@ template _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) { pointer __p = this->__begin_ + (__position - begin()); - // We can't compare unrelated pointers inside constant expressions - if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap()) { + if (this->__end_ < this->__end_cap()) { if (__p == this->__end_) { __construct_one_at_end(__x); } else { __move_range(__p, this->__end_, __p + 1); const_pointer __xr = pointer_traits::pointer_to(__x); - if (__p <= __xr && __xr < this->__end_) + if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x))) ++__xr; *__p = *__xr; }