]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add missing constraint to operator+ for std::move_iterator
authorJonathan Wakely <jwakely@redhat.com>
Thu, 14 Nov 2024 10:50:34 +0000 (10:50 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 14 Nov 2024 15:39:03 +0000 (15:39 +0000)
This constraint was added by the One Ranges proposal (P0896R4) and
then fixed by LWG 3293, but it was missing from libstdc++.

libstdc++-v3/ChangeLog:

* include/bits/stl_iterator.h (operator+): Add constraint to
move_iterator operator.
* testsuite/24_iterators/move_iterator/rel_ops_c++20.cc:

libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc

index 5ea901bf1f6c2f7701f1c6aa93e352fa513d7138..e872598d7d8f79d2d6492840b7a63eb8d6f4cedd 100644 (file)
@@ -1731,6 +1731,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline _GLIBCXX17_CONSTEXPR bool
     operator==(const move_iterator<_Iterator>& __x,
               const move_iterator<_Iterator>& __y)
+    // N.B. No contraints, x.base() == y.base() is always well-formed.
     { return __x.base() == __y.base(); }
 
 #ifdef __cpp_lib_three_way_comparison
@@ -1791,6 +1792,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline _GLIBCXX17_CONSTEXPR move_iterator<_Iterator>
     operator+(typename move_iterator<_Iterator>::difference_type __n,
              const move_iterator<_Iterator>& __x)
+#ifdef __glibcxx_concepts
+    requires requires { { __x.base() + __n } -> same_as<_Iterator>; }
+#endif
     { return __x + __n; }
 
   template<typename _Iterator>
index b2c1fe0e9f8dc704889db6bffee029d764af4381..deb177222578eb9a81a0a76da467d6c9718aa169 100644 (file)
@@ -18,6 +18,7 @@
 // { dg-do compile { target c++20 } }
 
 #include <iterator>
+#include <testsuite_iterators.h>
 
 template<int>
 struct Iter
@@ -141,3 +142,14 @@ static_assert( cend > beg );
 static_assert( beg <= cend );
 static_assert( cend >= beg );
 static_assert( std::is_lt(beg <=> cend) );
+
+template<typename I>
+  concept has_plus = requires(std::iter_difference_t<I> n, I i) {
+       { n + i } -> std::same_as<I>;
+  };
+
+using namespace __gnu_test;
+using MBI = std::move_iterator<bidirectional_iterator_wrapper<int>>;
+static_assert( ! has_plus<MBI> );
+using MRI = std::move_iterator<random_access_iterator_wrapper<int>>;
+static_assert( has_plus<MRI> );