[libcxx-commits] [libcxx] [libc++][ranges] LWG4083: `views::as_rvalue` should reject non-input ranges (PR #155156)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Aug 24 03:07:37 PDT 2025
https://github.com/H-G-Hristov created https://github.com/llvm/llvm-project/pull/155156
Fixes #105351
# References:
- https://wg21.link/LWG4083
- https://wg21.link/range.as.rvalue.overview
>From 4bd066d28d256644133fcb4415ef42dcc94e1fc4 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 24 Aug 2025 13:07:03 +0300
Subject: [PATCH] [libc++][ranges] LWG4083: `views::as_rvalue` should reject
non-input ranges
Fixes #105351
# References:
- https://wg21.link/LWG4083
- https://wg21.link/range.as.rvalue.overview
---
libcxx/docs/Status/Cxx2cIssues.csv | 2 +-
libcxx/include/__ranges/as_rvalue_view.h | 2 +-
.../range.adaptors/range.as.rvalue/adaptor.pass.cpp | 10 ++++++++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 6fcb2f3c78cfc..f843a6fafc6dc 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -70,7 +70,7 @@
"`LWG4076 <https://wg21.link/LWG4076>`__","``concat_view`` should be freestanding","2024-06 (St. Louis)","","",""
"`LWG4079 <https://wg21.link/LWG4079>`__","Missing Preconditions in ``concat_view::iterator``\`s conversion constructor","2024-06 (St. Louis)","","",""
"`LWG4082 <https://wg21.link/LWG4082>`__","``views::concat(r)`` is well-formed when ``r`` is an ``output_range``","2024-06 (St. Louis)","","",""
-"`LWG4083 <https://wg21.link/LWG4083>`__","``views::as_rvalue`` should reject non-input ranges","2024-06 (St. Louis)","","",""
+"`LWG4083 <https://wg21.link/LWG4083>`__","``views::as_rvalue`` should reject non-input ranges","2024-06 (St. Louis)","|Complete|","22",""
"`LWG4096 <https://wg21.link/LWG4096>`__","``views::iota(views::iota(0))`` should be rejected","2024-06 (St. Louis)","","",""
"`LWG4098 <https://wg21.link/LWG4098>`__","``views::adjacent<0>`` should reject non-forward ranges","2024-06 (St. Louis)","","",""
"`LWG4105 <https://wg21.link/LWG4105>`__","``ranges::ends_with``\`s Returns misses difference casting","2024-06 (St. Louis)","","",""
diff --git a/libcxx/include/__ranges/as_rvalue_view.h b/libcxx/include/__ranges/as_rvalue_view.h
index 5849a6c368396..08acf3d7736c6 100644
--- a/libcxx/include/__ranges/as_rvalue_view.h
+++ b/libcxx/include/__ranges/as_rvalue_view.h
@@ -117,7 +117,7 @@ struct __fn : __range_adaptor_closure<__fn> {
return /*---------------------------------*/ as_rvalue_view(std::forward<_Range>(__range));
}
- template <class _Range>
+ template <input_range _Range>
requires same_as<range_rvalue_reference_t<_Range>, range_reference_t<_Range>>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto
operator()(_Range&& __range) noexcept(noexcept(views::all(std::forward<_Range>(__range))))
diff --git a/libcxx/test/std/ranges/range.adaptors/range.as.rvalue/adaptor.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.as.rvalue/adaptor.pass.cpp
index dbe15238ebc86..88b28b0ec9832 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.as.rvalue/adaptor.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.as.rvalue/adaptor.pass.cpp
@@ -48,6 +48,16 @@ struct move_iterator_range {
static_assert(!std::ranges::view<move_iterator_range>);
static_assert(std::ranges::range<move_iterator_range>);
+// LWG4083: views::as_rvalue should reject non-input ranges
+struct I {
+ int operator*();
+ using difference_type = int;
+ I& operator++();
+ void operator++(int);
+};
+static_assert(
+ !HasPipe<decltype(std::ranges::subrange{I{}, std::unreachable_sentinel}), decltype(std::views::as_rvalue)>);
+
constexpr bool test() {
{ // view | views::as_rvalue
DefaultConstructibleView v{{}, 3};
More information about the libcxx-commits
mailing list