Skip to content

Commit

Permalink
[libc++] Use __is_pointer_in_range inside vector::insert
Browse files Browse the repository at this point in the history
  • Loading branch information
philnik777 committed Feb 6, 2024
1 parent 146e5ce commit 2853f48
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libcxx/include/vector
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 2853f48

Please sign in to comment.