From 1444b442eb81184f2b352b4ad30500b039ed6c52 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 12 Jan 2024 06:26:53 +0800 Subject: [PATCH] ``: Cast to the correct base type in `vector::_Orphan_range_unlocked` (#4276) --- stl/inc/vector | 28 ++++++++++++---------------- tests/libcxx/expected_results.txt | 4 ---- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/stl/inc/vector b/stl/inc/vector index b03e0348dc..e0010eef8b 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -2485,15 +2485,12 @@ protected: template 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; @@ -2510,7 +2507,7 @@ public: #if _ITERATOR_DEBUG_LEVEL != 0 const auto _Cont = static_cast(this->_Getcont()); _STL_VERIFY(_Cont, "cannot dereference value-initialized vector iterator"); - _STL_VERIFY(this->_Total_off(_Cont) < static_cast<_Difference_type>(_Cont->_Mysize), + _STL_VERIFY(this->_Total_off(_Cont) < static_cast(_Cont->_Mysize), "vector iterator not dereferenceable"); #endif // _ITERATOR_DEBUG_LEVEL != 0 @@ -2548,7 +2545,7 @@ public: if (_Off < 0) { _STL_VERIFY(-_Start_offset <= _Off, "cannot seek vector iterator before begin"); } else if (0 < _Off) { - _STL_VERIFY(_Off <= static_cast<_Difference_type>(_Cont->_Mysize - _Start_offset), + _STL_VERIFY(_Off <= static_cast(_Cont->_Mysize - _Start_offset), "cannot seek vector iterator after end"); } } @@ -2671,7 +2668,7 @@ public: #if _ITERATOR_DEBUG_LEVEL != 0 const auto _Cont = static_cast(this->_Getcont()); _STL_VERIFY(_Cont, "cannot increment value-initialized vector iterator"); - _STL_VERIFY(this->_Total_off(_Cont) < static_cast<_Difference_type>(_Cont->_Mysize), + _STL_VERIFY(this->_Total_off(_Cont) < static_cast(_Cont->_Mysize), "cannot increment vector end iterator"); #endif // _ITERATOR_DEBUG_LEVEL != 0 @@ -2687,9 +2684,8 @@ public: template 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; @@ -2706,7 +2702,7 @@ public: #if _ITERATOR_DEBUG_LEVEL != 0 const auto _Cont = static_cast(this->_Getcont()); _STL_VERIFY(_Cont, "cannot dereference value-initialized vector iterator"); - _STL_VERIFY(this->_Total_off(_Cont) < static_cast<_Difference_type>(_Cont->_Mysize), + _STL_VERIFY(this->_Total_off(_Cont) < static_cast(_Cont->_Mysize), "vector iterator not dereferenceable"); #endif // _ITERATOR_DEBUG_LEVEL != 0 @@ -3501,7 +3497,7 @@ public: _Iterator_base12** _Pnext = &this->_Myproxy->_Myfirstiter; while (*_Pnext) { // test offset from beginning of vector - const auto& _Pnextiter = static_cast(**_Pnext); + const auto& _Pnextiter = static_cast(**_Pnext); const auto _Temp = *_Pnext; if (!_Pnextiter._Myptr) { // orphan the iterator _Temp->_Myproxy = nullptr; diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index b8c1848b53..8f7d60b6f8 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -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/containers/sequences/vector.bool/emplace_back.pass.cpp FAIL - # Not analyzed. Looks like a test bug, assuming that hash> is constexpr. std/containers/sequences/vector.bool/enabled_hash.pass.cpp FAIL std/containers/sequences/vector.bool/vector_bool.pass.cpp FAIL