[libcxx-commits] [libcxx] 544f610 - [libc++] Use __is_pointer_in_range inside vector::insert (#80624)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 8 10:22:19 PST 2024


Author: Nikolas Klauser
Date: 2024-02-08T19:22:16+01:00
New Revision: 544f610d5310e1c1e7dd7a081d5a2a2607225740

URL: https://github.com/llvm/llvm-project/commit/544f610d5310e1c1e7dd7a081d5a2a2607225740
DIFF: https://github.com/llvm/llvm-project/commit/544f610d5310e1c1e7dd7a081d5a2a2607225740.diff

LOG: [libc++] Use __is_pointer_in_range inside vector::insert (#80624)

Added: 
    

Modified: 
    libcxx/include/vector

Removed: 
    


################################################################################
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<class T, class charT> requires is-vector-bool-reference<T> // 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 <class _Tp, class _Allocator>
 _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<const_pointer>::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;
     }


        


More information about the libcxx-commits mailing list