[libcxx-commits] [PATCH] D79343: [libc++][test] Adjust move_iterator tests to allow C++20

Casey Carter via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 4 11:15:59 PDT 2020


CaseyCarter created this revision.
CaseyCarter added reviewers: ldionne, EricWF, mclow.lists.
Herald added subscribers: libcxx-commits, broadwaylamb, dexonsmith.
Herald added a project: libc++.
Herald added a reviewer: libc++.

These tests fail due to a couple of changes to `move_iterator` for C++20:

1. `move_iterator<I>::operator++(int)` returns `void` in C++20 if `I` doesn't model `forward_iterator`.
2. `move_iterator<I>::reference` is calculated in C++20, so `I` must actually have an `operator*() const`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79343

Files:
  libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
  libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp


Index: libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
===================================================================
--- libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
+++ libcxx/test/std/iterators/predef.iterators/move.iterators/move.iterator/types.pass.cpp
@@ -30,11 +30,13 @@
 
 template <class ValueType, class Reference>
 struct DummyIt {
-  typedef std::forward_iterator_tag iterator_category;
-  typedef ValueType value_type;
-  typedef std::ptrdiff_t difference_type;
-  typedef ValueType* pointer;
-  typedef Reference reference;
+    typedef std::forward_iterator_tag iterator_category;
+    typedef ValueType value_type;
+    typedef std::ptrdiff_t difference_type;
+    typedef ValueType* pointer;
+    typedef Reference reference;
+
+    Reference operator*() const;
 };
 
 template <class It>
@@ -92,5 +94,5 @@
     }
 #endif
 
-  return 0;
+    return 0;
 }
Index: libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
===================================================================
--- libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
+++ libcxx/test/std/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.incr/post.pass.cpp
@@ -16,10 +16,22 @@
 
 #include <iterator>
 #include <cassert>
+#include <utility>
 
 #include "test_macros.h"
 #include "test_iterators.h"
 
+#if TEST_STD_VER > 17
+template <class It>
+void
+test_single_pass(It i, It x)
+{
+    std::move_iterator<It> r(std::move(i));
+    r++;
+    assert(std::move(r).base() == x);
+}
+#endif
+
 template <class It>
 void
 test(It i, It x)
@@ -33,7 +45,11 @@
 int main(int, char**)
 {
     char s[] = "123";
+#if TEST_STD_VER > 17
+    test_single_pass(input_iterator<char*>(s), input_iterator<char*>(s+1));
+#else
     test(input_iterator<char*>(s), input_iterator<char*>(s+1));
+#endif
     test(forward_iterator<char*>(s), forward_iterator<char*>(s+1));
     test(bidirectional_iterator<char*>(s), bidirectional_iterator<char*>(s+1));
     test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1));
@@ -52,5 +68,5 @@
     }
 #endif
 
-  return 0;
+    return 0;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79343.261874.patch
Type: text/x-patch
Size: 2275 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200504/3a8b04b8/attachment-0001.bin>


More information about the libcxx-commits mailing list