@@ -555,30 +555,20 @@ vector<bool, _Allocator>::__recommend(size_type __new_size) const {
555555template <class _Allocator >
556556inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
557557vector<bool , _Allocator>::__construct_at_end(size_type __n, bool __x) {
558- size_type __old_size = this -> __size_ ;
558+ iterator __old_end = end () ;
559559 this ->__size_ += __n;
560- if (__old_size == 0 || ((__old_size - 1 ) / __bits_per_word) != ((this ->__size_ - 1 ) / __bits_per_word)) {
561- if (this ->__size_ <= __bits_per_word)
562- this ->__begin_ [0 ] = __storage_type (0 );
563- else
564- this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
565- }
566- std::fill_n (__make_iter (__old_size), __n, __x);
560+ this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
561+ std::fill_n (__old_end, __n, __x);
567562}
568563
569564template <class _Allocator >
570565template <class _InputIterator , class _Sentinel >
571566_LIBCPP_CONSTEXPR_SINCE_CXX20 void
572567vector<bool , _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
573- size_type __old_size = this -> __size_ ;
568+ iterator __old_end = end () ;
574569 this ->__size_ += __n;
575- if (__old_size == 0 || ((__old_size - 1 ) / __bits_per_word) != ((this ->__size_ - 1 ) / __bits_per_word)) {
576- if (this ->__size_ <= __bits_per_word)
577- this ->__begin_ [0 ] = __storage_type (0 );
578- else
579- this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
580- }
581- std::__copy (__first, __last, __make_iter (__old_size));
570+ this ->__begin_ [(this ->__size_ - 1 ) / __bits_per_word] = __storage_type (0 );
571+ std::__copy (__first, __last, __old_end);
582572}
583573
584574template <class _Allocator >
@@ -852,7 +842,9 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type _
852842 this ->__throw_length_error ();
853843 vector __v (this ->get_allocator ());
854844 __v.__vallocate (__n);
855- __v.__construct_at_end (this ->begin (), this ->end (), this ->size ());
845+ // Ensure that the call to __construct_at_end(first, last, n) meets the precondition of n > 0
846+ if (this ->size () > 0 )
847+ __v.__construct_at_end (this ->begin (), this ->end (), this ->size ());
856848 swap (__v);
857849 }
858850}
0 commit comments