Skip to content

<algorithm>: ranges::stable_sort missing difference_type casting for pointer arithmetic #2885

Description

@hewillk

STL/stl/inc/algorithm

Lines 8149 to 8154 in ef62d3f

_Uninitialized_backout<iter_value_t<_It>*> _Backout{_Temp_ptr, _Temp_ptr + _Count};
iter_difference_t<_It> _Chunk_size = _Isort_max<_It>;
for (;;) {
// unconditionally merge elements back into the source buffer
_Chunk_size <<= 1;
_Chunked_merge_common(_Temp_ptr, _Temp_ptr + _Count, _First, _Chunk_size, _Count, _Pred, _Proj);

const auto _Backout_end = _Dest + _Count;

When _Count is an integer-class type, _Temp_ptr + _Count will be ill-formed.

#include <algorithm>
#include <ranges>
#include <vector>

int main() {
  std::vector<int> v;
  auto r = std::views::iota(0ULL, v.size())
         | std::views::transform([&v](auto i) -> auto& { return v[i]; });
  std::ranges::stable_sort(r);
}

https://godbolt.org/z/aPcq9Y6xh

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!rangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions