`<algorithm>`: `ranges::stable_sort` missing ` difference_type` casting for pointer arithmetic · Issue #2885 · microsoft/STL · GitHub
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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions