Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix truncation warnings in string/vector iterator subtraction and ranges::is_permutation #4237

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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