[libcxx-commits] [PATCH] D112631: [libc++][test] Fix invalid test for views::view_interface
Joe Loser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 27 09:14:07 PDT 2021
jloser created this revision.
jloser added reviewers: ldionne, Quuxplusone, Mordante, var-const.
jloser requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
The type `MoveOnlyForwardRange` violates the precondition stated in
`view.interface.general`. Specifically, the type passed to
`view_interface` shall model the `view` concept. In turn, this requires the
type to satisfy `movable` concept (and others), but this type
`MoveOnlyForwardRange` does not satisfy the `movable` concept.
Add a move assignment operator so that `MoveOnlyForwardRange` satisfies the
`movable` concept. While we're here, ensure the neighboring types that inherit
from `view_interface` also satisfy the `view` concept to avoid similar issues.
Fixes https://bugs.llvm.org/show_bug.cgi?id=50720
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D112631
Files:
libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
Index: libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
===================================================================
--- libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
+++ libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
@@ -68,15 +68,18 @@
constexpr ForwardIter begin() const { return ForwardIter(const_cast<int*>(buff)); }
constexpr ForwardIter end() const { return ForwardIter(const_cast<int*>(buff) + 8); }
};
+static_assert(std::ranges::view<ForwardRange>);
struct MoveOnlyForwardRange : std::ranges::view_interface<MoveOnlyForwardRange> {
int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7};
MoveOnlyForwardRange(MoveOnlyForwardRange const&) = delete;
MoveOnlyForwardRange(MoveOnlyForwardRange &&) = default;
+ MoveOnlyForwardRange& operator=(MoveOnlyForwardRange &&) = default;
MoveOnlyForwardRange() = default;
constexpr ForwardIter begin() const { return ForwardIter(const_cast<int*>(buff)); }
constexpr ForwardIter end() const { return ForwardIter(const_cast<int*>(buff) + 8); }
};
+static_assert(std::ranges::view<MoveOnlyForwardRange>);
struct EmptyIsTrue : std::ranges::view_interface<EmptyIsTrue> {
int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7};
@@ -84,6 +87,7 @@
constexpr ForwardIter end() const { return ForwardIter(const_cast<int*>(buff) + 8); }
constexpr bool empty() const { return true; }
};
+static_assert(std::ranges::view<EmptyIsTrue>);
struct SizeIsTen : std::ranges::view_interface<SizeIsTen> {
int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7};
@@ -91,6 +95,7 @@
constexpr ForwardIter end() const { return ForwardIter(const_cast<int*>(buff) + 8); }
constexpr size_t size() const { return 10; }
};
+static_assert(std::ranges::view<SizeIsTen>);
using RAIter = random_access_iterator<int*>;
@@ -99,6 +104,7 @@
constexpr RAIter begin() const { return RAIter(const_cast<int*>(buff)); }
constexpr RAIter end() const { return RAIter(const_cast<int*>(buff) + 8); }
};
+static_assert(std::ranges::view<RARange>);
using ContIter = contiguous_iterator<const int*>;
@@ -107,6 +113,7 @@
constexpr ContIter begin() const { return ContIter(buff); }
constexpr ContIter end() const { return ContIter(buff + 8); }
};
+static_assert(std::ranges::view<ContRange>);
struct DataIsNull : std::ranges::view_interface<DataIsNull> {
int buff[8] = {0, 1, 2, 3, 4, 5, 6, 7};
@@ -114,6 +121,7 @@
constexpr ContIter end() const { return ContIter(buff + 8); }
constexpr const int *data() const { return nullptr; }
};
+static_assert(std::ranges::view<DataIsNull>);
template<bool IsNoexcept>
struct BoolConvertibleComparison : std::ranges::view_interface<BoolConvertibleComparison<IsNoexcept>> {
@@ -136,6 +144,8 @@
constexpr ForwardIter begin() const noexcept { return ForwardIter(const_cast<int*>(buff)); }
constexpr SentinelType end() const noexcept { return SentinelType(const_cast<int*>(buff) + 8); }
};
+static_assert(std::ranges::view<BoolConvertibleComparison<true>>);
+static_assert(std::ranges::view<BoolConvertibleComparison<false>>);
template<class T>
concept EmptyInvocable = requires (T const& obj) { obj.empty(); };
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112631.382692.patch
Type: text/x-patch
Size: 3192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211027/4b309b72/attachment.bin>
More information about the libcxx-commits
mailing list