[libcxx-commits] [libcxx] c3cd5f5 - [libc++][test] Fix invalid test for views::view_interface

Joe Loser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 27 14:14:25 PDT 2021


Author: Joe Loser
Date: 2021-10-27T17:12:42-04:00
New Revision: c3cd5f5b4f8e78a04a49f5c1e40341110d21a593

URL: https://github.com/llvm/llvm-project/commit/c3cd5f5b4f8e78a04a49f5c1e40341110d21a593
DIFF: https://github.com/llvm/llvm-project/commit/c3cd5f5b4f8e78a04a49f5c1e40341110d21a593.diff

LOG: [libc++][test] Fix invalid test for views::view_interface

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

Reviewed By: Quuxplusone, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D112631

Added: 
    

Modified: 
    libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
index 99016c7755c97..bc2bc95c1c2d2 100644
--- a/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
+++ b/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp
@@ -68,15 +68,18 @@ struct ForwardRange : std::ranges::view_interface<ForwardRange> {
   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 @@ struct EmptyIsTrue : std::ranges::view_interface<EmptyIsTrue> {
   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 @@ struct SizeIsTen : std::ranges::view_interface<SizeIsTen> {
   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 @@ struct RARange : std::ranges::view_interface<RARange> {
   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 @@ struct ContRange : std::ranges::view_interface<ContRange> {
   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 @@ struct DataIsNull : std::ranges::view_interface<DataIsNull> {
   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 @@ struct BoolConvertibleComparison : std::ranges::view_interface<BoolConvertibleCo
   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(); };


        


More information about the libcxx-commits mailing list