[libcxx-commits] [PATCH] D156626: [libc++] Make the constraints as intended.
khjj via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 2 07:20:22 PDT 2023
K1ZeKaTo updated this revision to Diff 546454.
K1ZeKaTo retitled this revision from "Make the constraints as intended." to "[libc++] Make the constraints as intended.".
K1ZeKaTo added a comment.
The constraints do not work while rvalue.
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.verify.cpp
Index: libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.rvalue.verify.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.rvalue.verify.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 iterator_wrapper {
+public:
+ iterator_wrapper() = default;
+
+ constexpr explicit iterator_wrapper(I i) noexcept : base_(std::move(i)) {}
+
+ // This operator is used to check the constraints work.
+ constexpr auto&& operator*() && noexcept = delete;
+
+private:
+ I base_ = I{};
+};
+
+constexpr void test() {
+ std::array<int, 1> t1;
+ auto first = iterator_wrapper{std::move(t1)};
+
+ std::ranges::iter_move(std::move(first)); // expected-error and report as constraints not satisfied.
+}
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.546454.patch
Type: text/x-patch
Size: 2239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230802/a9e3b190/attachment.bin>
More information about the libcxx-commits
mailing list