@@ -275,17 +275,33 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
275
275
}
276
276
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crend () const _NOEXCEPT { return rend (); }
277
277
278
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator [](size_type __n) { return __make_ref (__n); }
278
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator [](size_type __n) {
279
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (__n < size (), " vector<bool>::operator[] index out of bounds" );
280
+ return __make_ref (__n);
281
+ }
279
282
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator [](size_type __n) const {
283
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (__n < size (), " vector<bool>::operator[] index out of bounds" );
280
284
return __make_ref (__n);
281
285
}
282
286
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at (size_type __n);
283
287
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at (size_type __n) const ;
284
288
285
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front () { return __make_ref (0 ); }
286
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front () const { return __make_ref (0 ); }
287
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back () { return __make_ref (__size_ - 1 ); }
288
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back () const { return __make_ref (__size_ - 1 ); }
289
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front () {
290
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (!empty (), " vector<bool>::front() called on an empty vector" );
291
+ return __make_ref (0 );
292
+ }
293
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front () const {
294
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (!empty (), " vector<bool>::front() called on an empty vector" );
295
+ return __make_ref (0 );
296
+ }
297
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back () {
298
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (!empty (), " vector<bool>::back() called on an empty vector" );
299
+ return __make_ref (__size_ - 1 );
300
+ }
301
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back () const {
302
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (!empty (), " vector<bool>::back() called on an empty vector" );
303
+ return __make_ref (__size_ - 1 );
304
+ }
289
305
290
306
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back (const value_type& __x);
291
307
#if _LIBCPP_STD_VER >= 14
@@ -310,7 +326,10 @@ class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
310
326
}
311
327
#endif
312
328
313
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back () { --__size_; }
329
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back () {
330
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (!empty (), " vector<bool>::pop_back called on an empty vector" );
331
+ --__size_;
332
+ }
314
333
315
334
#if _LIBCPP_STD_VER >= 14
316
335
template <class ... _Args>
@@ -995,6 +1014,8 @@ vector<bool, _Allocator>::__insert_with_size(
995
1014
template <class _Allocator >
996
1015
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool , _Allocator>::iterator
997
1016
vector<bool , _Allocator>::erase (const_iterator __position) {
1017
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (
1018
+ __position != end (), " vector<bool>::erase(iterator) called with a non-dereferenceable iterator" );
998
1019
iterator __r = __const_iterator_cast (__position);
999
1020
std::copy (__position + 1 , this ->cend (), __r);
1000
1021
--__size_;
@@ -1004,6 +1025,8 @@ vector<bool, _Allocator>::erase(const_iterator __position) {
1004
1025
template <class _Allocator >
1005
1026
_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool , _Allocator>::iterator
1006
1027
vector<bool , _Allocator>::erase (const_iterator __first, const_iterator __last) {
1028
+ _LIBCPP_ASSERT_VALID_INPUT_RANGE (
1029
+ __first <= __last, " vector<bool>::erase(iterator, iterator) called with an invalid range" );
1007
1030
iterator __r = __const_iterator_cast (__first);
1008
1031
difference_type __d = __last - __first;
1009
1032
std::copy (__last, this ->cend (), __r);
0 commit comments