Skip to content

Commit

Permalink
<vector>: Cast to the correct base type in `vector<bool, Alloc>::_O…
Browse files Browse the repository at this point in the history
…rphan_range_unlocked` (#4276)
  • Loading branch information
frederick-vs-ja authored Jan 11, 2024
1 parent 9ab77b9 commit 1444b44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
28 changes: 12 additions & 16 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -2485,15 +2485,12 @@ protected:

template <class _Alvbase_wrapped>
class _Vb_const_iterator : public _Vb_iter_base<_Alvbase_wrapped> {
private:
using _Mybase = _Vb_iter_base<_Alvbase_wrapped>;

public:
using _Mycont = typename _Mybase::_Mycont;
using _Difference_type = typename _Mybase::_Difference_type;
using _Size_type = typename _Mybase::_Size_type;
using _Reft = _Vb_reference<_Alvbase_wrapped>;
using const_reference = bool;
using _Mybase = _Vb_iter_base<_Alvbase_wrapped>;
using _Mycont = typename _Mybase::_Mycont;
using _Size_type = typename _Mybase::_Size_type;
using _Reft = _Vb_reference<_Alvbase_wrapped>;
using const_reference = bool;

using iterator_category = random_access_iterator_tag;
using value_type = bool;
Expand All @@ -2510,7 +2507,7 @@ public:
#if _ITERATOR_DEBUG_LEVEL != 0
const auto _Cont = static_cast<const _Mycont*>(this->_Getcont());
_STL_VERIFY(_Cont, "cannot dereference value-initialized vector<bool> iterator");
_STL_VERIFY(this->_Total_off(_Cont) < static_cast<_Difference_type>(_Cont->_Mysize),
_STL_VERIFY(this->_Total_off(_Cont) < static_cast<difference_type>(_Cont->_Mysize),
"vector<bool> iterator not dereferenceable");
#endif // _ITERATOR_DEBUG_LEVEL != 0

Expand Down Expand Up @@ -2548,7 +2545,7 @@ public:
if (_Off < 0) {
_STL_VERIFY(-_Start_offset <= _Off, "cannot seek vector<bool> iterator before begin");
} else if (0 < _Off) {
_STL_VERIFY(_Off <= static_cast<_Difference_type>(_Cont->_Mysize - _Start_offset),
_STL_VERIFY(_Off <= static_cast<difference_type>(_Cont->_Mysize - _Start_offset),
"cannot seek vector<bool> iterator after end");
}
}
Expand Down Expand Up @@ -2671,7 +2668,7 @@ public:
#if _ITERATOR_DEBUG_LEVEL != 0
const auto _Cont = static_cast<const _Mycont*>(this->_Getcont());
_STL_VERIFY(_Cont, "cannot increment value-initialized vector<bool> iterator");
_STL_VERIFY(this->_Total_off(_Cont) < static_cast<_Difference_type>(_Cont->_Mysize),
_STL_VERIFY(this->_Total_off(_Cont) < static_cast<difference_type>(_Cont->_Mysize),
"cannot increment vector<bool> end iterator");
#endif // _ITERATOR_DEBUG_LEVEL != 0

Expand All @@ -2687,9 +2684,8 @@ public:
template <class _Alvbase_wrapped>
class _Vb_iterator : public _Vb_const_iterator<_Alvbase_wrapped> {
public:
using _Mybase = _Vb_const_iterator<_Alvbase_wrapped>;
using _Mycont = typename _Mybase::_Mycont;
using _Difference_type = typename _Mybase::_Difference_type;
using _Mybase = _Vb_const_iterator<_Alvbase_wrapped>;
using _Mycont = typename _Mybase::_Mycont;

using _Reft = _Vb_reference<_Alvbase_wrapped>;
using const_reference = bool;
Expand All @@ -2706,7 +2702,7 @@ public:
#if _ITERATOR_DEBUG_LEVEL != 0
const auto _Cont = static_cast<const _Mycont*>(this->_Getcont());
_STL_VERIFY(_Cont, "cannot dereference value-initialized vector<bool> iterator");
_STL_VERIFY(this->_Total_off(_Cont) < static_cast<_Difference_type>(_Cont->_Mysize),
_STL_VERIFY(this->_Total_off(_Cont) < static_cast<difference_type>(_Cont->_Mysize),
"vector<bool> iterator not dereferenceable");
#endif // _ITERATOR_DEBUG_LEVEL != 0

Expand Down Expand Up @@ -3501,7 +3497,7 @@ public:

_Iterator_base12** _Pnext = &this->_Myproxy->_Myfirstiter;
while (*_Pnext) { // test offset from beginning of vector
const auto& _Pnextiter = static_cast<const_iterator&>(**_Pnext);
const auto& _Pnextiter = static_cast<typename const_iterator::_Mybase&>(**_Pnext);
const auto _Temp = *_Pnext;
if (!_Pnextiter._Myptr) { // orphan the iterator
_Temp->_Myproxy = nullptr;
Expand Down
4 changes: 0 additions & 4 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,6 @@ std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp:1 FAIL
std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp:0 FAIL
std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp:1 FAIL

# Not analyzed. Possible STL bug, _Vb_reference derives from _Vb_iter_base and is adopted by the container, but _Orphan_range_unlocked assumes every child is a const_iterator.
# note: failure was caused by cast of object of dynamic type 'Ref' to type 'const std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>'
std/containers/sequences/vector.bool/emplace_back.pass.cpp FAIL

# Not analyzed. Looks like a test bug, assuming that hash<vector<bool>> is constexpr.
std/containers/sequences/vector.bool/enabled_hash.pass.cpp FAIL
std/containers/sequences/vector.bool/vector_bool.pass.cpp FAIL
Expand Down

0 comments on commit 1444b44

Please sign in to comment.