Skip to content

Commit

Permalink
Fix truncation warnings in string/vector iterator subtraction and…
Browse files Browse the repository at this point in the history
… `ranges::is_permutation` (#4237)
  • Loading branch information
StephanTLavavej authored Dec 7, 2023
1 parent b351b67 commit ae50dff
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ namespace ranges {
if constexpr (bidirectional_iterator<_It1> && bidirectional_iterator<_It2>) {
// determine final iterator values
auto _Final1 = _RANGES _Find_last_iterator(_First1, _Last1, _Count);
auto _Final2 = _RANGES _Find_last_iterator(_First2, _Last2, _Count);
using _Diff2 = iter_difference_t<_It2>; // avoid truncation warnings; ranges are the same length
auto _Final2 = _RANGES _Find_last_iterator(_First2, _Last2, static_cast<_Diff2>(_Count));

for (;;) { // trim matching suffixes
--_Final1;
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public:

_NODISCARD _CONSTEXPR20 difference_type operator-(const _Vector_const_iterator& _Right) const noexcept {
_Compat(_Right);
return _Ptr - _Right._Ptr;
return static_cast<difference_type>(_Ptr - _Right._Ptr);
}

_NODISCARD _CONSTEXPR20 reference operator[](const difference_type _Off) const noexcept {
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xstring
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ public:

_NODISCARD _CONSTEXPR20 difference_type operator-(const _String_const_iterator& _Right) const noexcept {
_Compat(_Right);
return _Ptr - _Right._Ptr;
return static_cast<difference_type>(_Ptr - _Right._Ptr);
}

_NODISCARD _CONSTEXPR20 reference operator[](const difference_type _Off) const noexcept {
Expand Down

0 comments on commit ae50dff

Please sign in to comment.