From e4e6ae8a50a93d3b41cc15975e9c8c23dfdc7490 Mon Sep 17 00:00:00 2001 From: Xiaoyang Liu Date: Mon, 8 Apr 2024 00:12:10 -0700 Subject: [PATCH 1/3] [libc++][ranges] LWG3984: 'ranges::to''s recursion branch may be ill-formed --- libcxx/docs/Status/Cxx2cIssues.csv | 2 +- libcxx/include/__ranges/to.h | 2 +- .../std/ranges/range.utility/range.utility.conv/to.pass.cpp | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv index 8a4bf2ef62162..d91fff7c8687e 100644 --- a/libcxx/docs/Status/Cxx2cIssues.csv +++ b/libcxx/docs/Status/Cxx2cIssues.csv @@ -44,7 +44,7 @@ "`3919 `__","``enumerate_view`` may invoke UB for sized common non-forward underlying ranges","Tokyo March 2024","","","|ranges|" "`3950 `__","``std::basic_string_view`` comparison operators are overspecified","Tokyo March 2024","|Complete|","18.0","" "`3975 `__","Specializations of ``basic_format_context`` should not be permitted","Tokyo March 2024","|Nothing To Do|","","|format|" -"`3984 `__","``ranges::to``'s recursion branch may be ill-formed","Tokyo March 2024","","","|ranges|" +"`3984 `__","``ranges::to``'s recursion branch may be ill-formed","Tokyo March 2024","|Complete|","19.0","|ranges|" "`4011 `__","``""Effects: Equivalent to return""`` in ``[span.elem]``","Tokyo March 2024","|Nothing To Do|","","" "`4012 `__","``common_view::begin/end`` are missing the ``simple-view`` check","Tokyo March 2024","","","|ranges|" "`4013 `__","``lazy_split_view::outer-iterator::value_type`` should not provide default constructor","Tokyo March 2024","","","|ranges|" diff --git a/libcxx/include/__ranges/to.h b/libcxx/include/__ranges/to.h index 67818c521b150..014e12a50f650 100644 --- a/libcxx/include/__ranges/to.h +++ b/libcxx/include/__ranges/to.h @@ -129,7 +129,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Container to(_Range&& __r // Try the recursive case. } else if constexpr (input_range>) { return ranges::to<_Container>( - __range | views::transform([](auto&& __elem) { + ranges::ref_view(__range) | views::transform([](auto&& __elem) { return ranges::to>(std::forward(__elem)); }), std::forward<_Args>(__args)...); diff --git a/libcxx/test/std/ranges/range.utility/range.utility.conv/to.pass.cpp b/libcxx/test/std/ranges/range.utility/range.utility.conv/to.pass.cpp index 3df88d6a2dcc3..7f816bb21a197 100644 --- a/libcxx/test/std/ranges/range.utility/range.utility.conv/to.pass.cpp +++ b/libcxx/test/std/ranges/range.utility/range.utility.conv/to.pass.cpp @@ -560,6 +560,11 @@ constexpr void test_recursive() { } assert((in | std::ranges::to()) == result); + + // LWG3984: ranges::to's recursion branch may be ill-formed + auto in_owning_view = std::views::all(std::move(in)); + static_assert(!std::ranges::viewable_range); + assert(std::ranges::to(in_owning_view) == result); } constexpr bool test() { From a80f564d00d27fe8a1c92a83bf669b6a9da04f35 Mon Sep 17 00:00:00 2001 From: Xiaoyang Liu Date: Mon, 8 Apr 2024 00:18:15 -0700 Subject: [PATCH 2/3] [libc++][ranges] LWG3984: 'ranges::to''s recursion branch may be ill-formed --- libcxx/include/__ranges/to.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libcxx/include/__ranges/to.h b/libcxx/include/__ranges/to.h index 014e12a50f650..7d042b196f6a5 100644 --- a/libcxx/include/__ranges/to.h +++ b/libcxx/include/__ranges/to.h @@ -24,6 +24,7 @@ #include <__ranges/concepts.h> #include <__ranges/from_range.h> #include <__ranges/range_adaptor.h> +#include <__ranges/ref_view.h> #include <__ranges/size.h> #include <__ranges/transform_view.h> #include <__type_traits/add_pointer.h> From f363d98e7553e173daba42414bacfd53e8a348c3 Mon Sep 17 00:00:00 2001 From: Xiaoyang Liu Date: Wed, 10 Apr 2024 23:23:25 -0400 Subject: [PATCH 3/3] [libc++][ranges] LWG3984: 'ranges::to''s recursion branch may be ill-formed Co-authored-by: A. Jiang --- libcxx/include/__ranges/to.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcxx/include/__ranges/to.h b/libcxx/include/__ranges/to.h index 7d042b196f6a5..e282ef2e4898d 100644 --- a/libcxx/include/__ranges/to.h +++ b/libcxx/include/__ranges/to.h @@ -130,7 +130,7 @@ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Container to(_Range&& __r // Try the recursive case. } else if constexpr (input_range>) { return ranges::to<_Container>( - ranges::ref_view(__range) | views::transform([](auto&& __elem) { + ref_view(__range) | views::transform([](auto&& __elem) { return ranges::to>(std::forward(__elem)); }), std::forward<_Args>(__args)...);