Skip to content

Commit df78e28

Browse files
authored
[libc++] Use __is_address_in_range in vector (#139032)
This avoids a branch in `vector`s code on whether we're constant evaluating, which improves our coverage of constant-evaluated code.
1 parent 74ed334 commit df78e28

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

libcxx/include/__vector/vector.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,8 +1259,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
12591259
vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) {
12601260
pointer __p = this->__begin_ + (__position - begin());
12611261
if (__n > 0) {
1262-
// We can't compare unrelated pointers inside constant expressions
1263-
if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__cap_ - this->__end_)) {
1262+
if (__n <= static_cast<size_type>(this->__cap_ - this->__end_)) {
12641263
size_type __old_n = __n;
12651264
pointer __old_last = this->__end_;
12661265
if (__n > static_cast<size_type>(this->__end_ - __p)) {
@@ -1271,7 +1270,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
12711270
if (__n > 0) {
12721271
__move_range(__p, __old_last, __p + __old_n);
12731272
const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1274-
if (__p <= __xr && __xr < this->__end_)
1273+
if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))
12751274
__xr += __old_n;
12761275
std::fill_n(__p, __n, *__xr);
12771276
}

0 commit comments

Comments
 (0)