https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100795
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2021-05-27 00:00:00 |2024-11-13 --- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #11) > *** Bug 117552 has been marked as a duplicate of this bug. *** >From that dup ... The following example doesn't compile with libstdc++. Godbolt link: https://godbolt.org/z/67Tanfxad ``` #include <cstdint> #include <algorithm> #include <ranges> constinit int a[]{42, 1729}; constinit auto view32 = std::views::iota(std::uint32_t{}, std::uint32_t{}) | std::views::transform([] (std::uint32_t i) -> int& { return a[i]; }); 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::sort(view32); std::ranges::sort(viewmax); std::ranges::stable_sort(view32); std::ranges::stable_sort(viewmax); } ``` There're at least 3 issues concentratedly appearing in sorting algorithms. 1. make_unsigned_t is mistakenly used for difference type that is an integer-class type. 2. iterator_traits<It>::value_type is calculated to be void for some C++20-only iterators. Such calculation might be still right, but iter_value_t should be used in these cases. 3. These algorithms use tag dispatch based on iterator_traits<It>::iterator_category, which is almost always wrong when the view is produced via views::iota. Presumably, there might be a common cause - these ranges algorithms are using non-ranges versions too eagerly.