[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
Wed Jun 22 01:50:46 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG20869c5ba069: [libc++] fix views::all hard error on lvalue move only views instead of SFINAE (authored by huixie90).

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.438942.patch
Type: text/x-patch
Size: 1897 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220622/ebc09c7f/attachment.bin>


More information about the libcxx-commits mailing list