Skip to content

Commit 759a2ac

Browse files
authored
[libc++][ranges] LWG4083: views::as_rvalue should reject non-input ranges (#155156)
Fixes #105351 # References: - https://wg21.link/LWG4083 - https://wg21.link/range.as.rvalue.overview
1 parent cd7f7cf commit 759a2ac

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

libcxx/docs/Status/Cxx2cIssues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"`LWG4076 <https://wg21.link/LWG4076>`__","``concat_view`` should be freestanding","2024-06 (St. Louis)","","",""
7171
"`LWG4079 <https://wg21.link/LWG4079>`__","Missing Preconditions in ``concat_view::iterator``\`s conversion constructor","2024-06 (St. Louis)","","",""
7272
"`LWG4082 <https://wg21.link/LWG4082>`__","``views::concat(r)`` is well-formed when ``r`` is an ``output_range``","2024-06 (St. Louis)","","",""
73-
"`LWG4083 <https://wg21.link/LWG4083>`__","``views::as_rvalue`` should reject non-input ranges","2024-06 (St. Louis)","","",""
73+
"`LWG4083 <https://wg21.link/LWG4083>`__","``views::as_rvalue`` should reject non-input ranges","2024-06 (St. Louis)","|Complete|","22",""
7474
"`LWG4096 <https://wg21.link/LWG4096>`__","``views::iota(views::iota(0))`` should be rejected","2024-06 (St. Louis)","|Complete|","22",""
7575
"`LWG4098 <https://wg21.link/LWG4098>`__","``views::adjacent<0>`` should reject non-forward ranges","2024-06 (St. Louis)","","",""
7676
"`LWG4105 <https://wg21.link/LWG4105>`__","``ranges::ends_with``\`s Returns misses difference casting","2024-06 (St. Louis)","","",""

libcxx/include/__ranges/as_rvalue_view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct __fn : __range_adaptor_closure<__fn> {
117117
return /*---------------------------------*/ as_rvalue_view(std::forward<_Range>(__range));
118118
}
119119

120-
template <class _Range>
120+
template <input_range _Range>
121121
requires same_as<range_rvalue_reference_t<_Range>, range_reference_t<_Range>>
122122
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static constexpr auto
123123
operator()(_Range&& __range) noexcept(noexcept(views::all(std::forward<_Range>(__range))))

libcxx/test/std/ranges/range.adaptors/range.as.rvalue/adaptor.pass.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ struct move_iterator_range {
4848
static_assert(!std::ranges::view<move_iterator_range>);
4949
static_assert(std::ranges::range<move_iterator_range>);
5050

51+
// LWG4083: views::as_rvalue should reject non-input ranges
52+
struct I {
53+
int operator*();
54+
using difference_type = int;
55+
I& operator++();
56+
void operator++(int);
57+
};
58+
static_assert(!std::is_invocable_v<decltype(std::views::as_rvalue),
59+
decltype(std::ranges::subrange{I{}, std::unreachable_sentinel})>);
60+
static_assert(
61+
!HasPipe<decltype(std::ranges::subrange{I{}, std::unreachable_sentinel}), decltype(std::views::as_rvalue)>);
62+
5163
constexpr bool test() {
5264
{ // view | views::as_rvalue
5365
DefaultConstructibleView v{{}, 3};

0 commit comments

Comments
 (0)