@@ -536,30 +536,20 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
536
536
template <class _Allocator >
537
537
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
538
538
vector<bool , _Allocator>::__construct_at_end(size_type __n, bool __x) {
539
- size_type __old_size = this -> __size_ ;
539
+ iterator __old_end = end () ;
540
540
this ->__size_ += __n;
541
- if (__old_size == 0 || ((__old_size - 1 ) / __bits_per_word) != ((this ->__size_ - 1 ) / __bits_per_word)) {
542
- if (this ->__size_ <= __bits_per_word)
543
- this ->__begin_ [0 ] = __storage_type (0 );
544
- else
545
- this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
546
- }
547
- std::fill_n (__make_iter (__old_size), __n, __x);
541
+ this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
542
+ std::fill_n (__old_end, __n, __x);
548
543
}
549
544
550
545
template <class _Allocator >
551
546
template <class _InputIterator , class _Sentinel >
552
547
_LIBCPP_CONSTEXPR_SINCE_CXX20 void
553
548
vector<bool , _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
554
- size_type __old_size = this -> __size_ ;
549
+ iterator __old_end = end () ;
555
550
this ->__size_ += __n;
556
- if (__old_size == 0 || ((__old_size - 1 ) / __bits_per_word) != ((this ->__size_ - 1 ) / __bits_per_word)) {
557
- if (this ->__size_ <= __bits_per_word)
558
- this ->__begin_ [0 ] = __storage_type (0 );
559
- else
560
- this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
561
- }
562
- std::__copy (__first, __last, __make_iter (__old_size));
551
+ this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
552
+ std::__copy (__first, __last, __old_end);
563
553
}
564
554
565
555
template <class _Allocator >
@@ -833,7 +823,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type _
833
823
this ->__throw_length_error ();
834
824
vector __v (this ->get_allocator ());
835
825
__v.__vallocate (__n);
836
- __v.__construct_at_end (this ->begin (), this ->end (), this ->size ());
826
+ // Ensure that the call to __construct_at_end(first, last, n) meets the precondition of n > 0
827
+ if (this ->size () > 0 )
828
+ __v.__construct_at_end (this ->begin (), this ->end (), this ->size ());
837
829
swap (__v);
838
830
}
839
831
}
0 commit comments