On Mon, 20 Oct 2025 at 15:04, Jonathan Wakely <[email protected]> wrote: > > On Wed, 15 Oct 2025 at 16:23, Yuao Ma <[email protected]> wrote: > > > > Hi Jonathan, > > > > Thanks for the information about the standard wording. Regarding this > > patch, I'm wondering does it need any further refinement? > > No, I don't think you need to make any changes.
I see this was pushed to trunk - please wait for explicit approval. My last mail probably wasn't very clear, but I hadn't finished a final review. Not a big deal, since the patch is good. It turns out another change is needed though, because the test failure you got with __max_size_type should be SFINAE-friendly, because indices(1) should be expression equivalent to iota(0, 1). I'm testing this fix: Author: Jonathan Wakely <[email protected]> AuthorDate: Tue Oct 21 21:21:45 2025 Commit: Jonathan Wakely <[email protected]> CommitDate: Tue Oct 21 21:21:45 2025 libstdc++: Add missing constraints to views::indices Calling views::indices(n) should be expression equivalent to views::iota(decltype(n)(0), n), which means it should have the same constraints as views::iota and be SFINAE-friendly. libstdc++-v3/ChangeLog: * include/std/ranges (indices::operator()): Constrain using __can_iota_view concept. * testsuite/std/ranges/indices/1.cc: Check SFINAE-friendliness required by expression equivalence. diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 25d2e28e72ff..158692d92a70 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -791,6 +791,7 @@ namespace views struct _Indices { template<ranges::__detail::__is_integer_like _Tp> + requires __detail::__can_iota_view<_Tp> [[nodiscard]] constexpr auto operator() (_Tp __e) const noexcept { return iota(_Tp{}, __e); } diff --git a/libstdc++-v3/testsuite/std/ranges/indices/1.cc b/libstdc++-v3/testsuite/std/ranges/indices/1.cc index 805b29e358f7..0b5ed3a37afc 100644 --- a/libstdc++-v3/testsuite/std/ranges/indices/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/indices/1.cc @@ -29,3 +29,17 @@ int main() { VERIFY(test<size_t>(44)); static_assert(test<size_t>(44)); } + +template<typename T> +constexpr bool test_wider(T n) +{ + // If indices(n) works, try again with ranges::distance(indices(n)), + // which will be a wider type, until we get to an unsupported type. + // This verifies that indices(n) is SFINAE-friendly, because otherwise we + // would get a hard error outside the immediate context checked by requires. + if constexpr (requires { std::views::indices(n); }) + test_wider(std::ranges::distance(std::views::indices(n))); + return true; +} + +static_assert(test_wider(0));
