microsoft / STL

MSVC's implementation of the C++ Standard Library.
Other
10.2k stars 1.51k forks source link

`<algorithm>`: `ranges::stable_sort` fails to accept ranges whose difference type is an integer-class type #5083

Closed frederick-vs-ja closed 23 hours ago

frederick-vs-ja commented 23 hours ago

Describe the bug

The following program doesn't compile with MSVC STL.

#include <cstdint>
#include <algorithm>
#include <ranges>

constinit int a[]{42, 1729};
constinit auto viewmax =
    std::views::iota(std::uintmax_t{}, std::uintmax_t{}) |
    std::views::transform([] (std::uintmax_t i) -> int& { return a[i]; });

int main()
{
    std::ranges::stable_sort(viewmax);
}

The errors are probably caused by adding integer-class value to pointer, which is not supported.

Command-line test case

https://godbolt.org/z/q5vdzzMqK

Expected behavior

The program compiles.

STL version

Every version shipping integer-class types (_Signed128/_Unsigned128).

The program used to compile in VS 16.10 which didn't have integer-class types (Godbolt link).

Additional context

frederick-vs-ja commented 23 hours ago

Oops, this is duplicate of #2885.