[libcxx-commits] [PATCH] D128281: [libc++] fix views::all hard error on lvalue move only views instead of SFINAE

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 21 13:32:58 PDT 2022


huixie90 updated this revision to Diff 438816.
huixie90 added a comment.

pull rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128281/new/

https://reviews.llvm.org/D128281

Files:
  libcxx/include/__ranges/all.h
  libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp


Index: libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp
===================================================================
--- libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp
+++ libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp
@@ -49,6 +49,17 @@
 static_assert(std::ranges::view<CopyableView<true>>);
 static_assert(std::ranges::view<CopyableView<false>>);
 
+struct MoveOnlyView : std::ranges::view_base{
+  MoveOnlyView() = default;
+  MoveOnlyView(const MoveOnlyView&) = delete;
+  MoveOnlyView& operator=(const MoveOnlyView&) = delete;
+  MoveOnlyView(MoveOnlyView&&) = default;
+  MoveOnlyView& operator=(MoveOnlyView&&) = default;
+
+  int* begin() const;
+  int* end() const;
+};
+
 struct Range {
   int start_;
   constexpr explicit Range(int start) noexcept : start_(start) {}
@@ -139,6 +150,11 @@
   {
     static_assert(!std::is_invocable_v<decltype(std::views::all)>);
     static_assert(!std::is_invocable_v<decltype(std::views::all), RandomAccessRange, RandomAccessRange>);
+
+    // `views::all(v)` is expression equivalent to `decay-copy(v)` if the decayed type 
+    // of `v` models `view`. If `v` is an lvalue-reference to a move-only view, the 
+    // expression should be ill-formed because `v` is not copyable
+    static_assert(!std::is_invocable_v<decltype(std::views::all), MoveOnlyView&>);
   }
 
   // Test that std::views::all is a range adaptor
Index: libcxx/include/__ranges/all.h
===================================================================
--- libcxx/include/__ranges/all.h
+++ libcxx/include/__ranges/all.h
@@ -39,6 +39,7 @@
     [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
     constexpr auto operator()(_Tp&& __t) const
       noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t))))
+      -> decltype(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))
     {
       return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t));
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128281.438816.patch
Type: text/x-patch
Size: 1897 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220621/6bf34540/attachment.bin>


More information about the libcxx-commits mailing list