[libcxx-commits] [PATCH] D156626: [libc++] Make the constraints as intended.

khjj via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Aug 5 02:03:38 PDT 2023


K1ZeKaTo updated this revision to Diff 547466.

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

https://reviews.llvm.org/D156626

Files:
  libcxx/include/__iterator/iter_move.h
  libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move_rvalue.compile.pass.cpp


Index: libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move_rvalue.compile.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move_rvalue.compile.pass.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// Test the constraints in libc++.
+
+// template<class I>
+// unspecified iter_move;
+
+#include <array>
+#include <utility>
+#include <iterator>
+
+template <typename I>
+class wrapper {
+public:
+  wrapper() = default;
+
+  constexpr explicit wrapper(I i) noexcept : base_(std::move(i)) {}
+
+  // This operator is used to check the constraints work.
+  constexpr decltype(auto) operator*() & noexcept { return base_; }
+
+  // This operator is used to check the constraints work.
+  constexpr auto&& operator*() && noexcept = delete;
+
+private:
+  I base_ = I{};
+};
+
+template <typename I>
+wrapper(I) -> wrapper<I>;
+
+void test_iter_move_rvalue() {
+  std::array<int, 1> t1;
+  auto first = wrapper{std::move(t1)};
+
+  auto helper = [](auto&& f) requires (!requires{std::ranges::iter_move(std::move(f));}) {};
+  [[maybe_unused]] auto dummy = std::ranges::iter_move(first);
+  helper(first);
+}
Index: libcxx/include/__iterator/iter_move.h
===================================================================
--- libcxx/include/__iterator/iter_move.h
+++ libcxx/include/__iterator/iter_move.h
@@ -49,8 +49,8 @@
 concept __move_deref =
   !__unqualified_iter_move<_Tp> &&
   requires (_Tp&& __t) {
-    *__t;
-    requires is_lvalue_reference_v<decltype(*__t)>;
+    *std::forward<_Tp>(__t);
+    requires is_lvalue_reference_v<decltype(*std::forward<_Tp>(__t))>;
   };
 
 template<class _Tp>
@@ -58,8 +58,8 @@
   !__unqualified_iter_move<_Tp> &&
   !__move_deref<_Tp> &&
   requires (_Tp&& __t) {
-    *__t;
-    requires (!is_lvalue_reference_v<decltype(*__t)>);
+    *std::forward<_Tp>(__t);
+    requires (!is_lvalue_reference_v<decltype(*std::forward<_Tp>(__t))>);
   };
 
 // [iterator.cust.move]


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156626.547466.patch
Type: text/x-patch
Size: 2476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230805/a498af9b/attachment.bin>


More information about the libcxx-commits mailing list