@@ -558,30 +558,20 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
558558template <class _Allocator >
559559inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
560560vector<bool , _Allocator>::__construct_at_end(size_type __n, bool __x) {
561- size_type __old_size = this -> __size_ ;
561+ iterator __old_end = end () ;
562562 this ->__size_ += __n;
563- if (__old_size == 0 || ((__old_size - 1 ) / __bits_per_word) != ((this ->__size_ - 1 ) / __bits_per_word)) {
564- if (this ->__size_ <= __bits_per_word)
565- this ->__begin_ [0 ] = __storage_type (0 );
566- else
567- this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
568- }
569- std::fill_n (__make_iter (__old_size), __n, __x);
563+ this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
564+ std::fill_n (__old_end, __n, __x);
570565}
571566
572567template <class _Allocator >
573568template <class _InputIterator , class _Sentinel >
574569_LIBCPP_CONSTEXPR_SINCE_CXX20 void
575570vector<bool , _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
576- size_type __old_size = this -> __size_ ;
571+ iterator __old_end = end () ;
577572 this ->__size_ += __n;
578- if (__old_size == 0 || ((__old_size - 1 ) / __bits_per_word) != ((this ->__size_ - 1 ) / __bits_per_word)) {
579- if (this ->__size_ <= __bits_per_word)
580- this ->__begin_ [0 ] = __storage_type (0 );
581- else
582- this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
583- }
584- std::__copy (std::move (__first), std::move (__last), __make_iter (__old_size));
573+ this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
574+ std::__copy (std::move (__first), std::move (__last), __old_end);
585575}
586576
587577template <class _Allocator >
@@ -855,7 +845,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type _
855845 this ->__throw_length_error ();
856846 vector __v (this ->get_allocator ());
857847 __v.__vallocate (__n);
858- __v.__construct_at_end (this ->begin (), this ->end (), this ->size ());
848+ // Ensure that the call to __construct_at_end(first, last, n) meets the precondition of n > 0
849+ if (this ->size () > 0 )
850+ __v.__construct_at_end (this ->begin (), this ->end (), this ->size ());
859851 swap (__v);
860852 }
861853}
0 commit comments