[libcxx-commits] [libcxx] [libc++] Fix `reverse_iterator` when underlying is c++20 `bidirectional_iterator` but not `Cpp17BidirectionalIterator` (PR #112100)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Oct 13 02:55:41 PDT 2024
https://github.com/huixie90 updated https://github.com/llvm/llvm-project/pull/112100
>From 9d322c29c1d7e18abb0126cc7ef40ecb73fdd8ac Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Sat, 12 Oct 2024 16:21:55 +0100
Subject: [PATCH 1/2] [libc++] Fix `reverse_iterator` when underlying is c++20
bidirectional_iterator but not c++17 BidirectionalIterator
---
libcxx/include/__iterator/reverse_iterator.h | 6 +-
.../reverse.iter.cmp/equal.pass.cpp | 4 +
.../reverse.iter.cmp/greater-equal.pass.cpp | 5 ++
.../reverse.iter.cmp/greater.pass.cpp | 5 ++
.../reverse.iter.cmp/less-equal.pass.cpp | 5 ++
.../reverse.iter.cmp/less.pass.cpp | 5 ++
.../reverse.iter.cmp/not-equal.pass.cpp | 4 +
.../reverse.iter.cons/assign.pass.cpp | 3 +
.../reverse.iter.cons/ctor.default.pass.cpp | 3 +
.../reverse.iter.cons/ctor.iter.pass.cpp | 3 +
.../ctor.reverse_iterator.pass.cpp | 3 +
.../reverse.iter.conv/base.pass.cpp | 18 +++--
.../reverse.iter.elem/arrow.pass.cpp | 58 ++++++++++++++
.../reverse.iter.elem/bracket.pass.cpp | 4 +
.../reverse.iter.elem/dereference.pass.cpp | 5 ++
.../decrement-assign.pass.cpp | 3 +
.../increment-assign.pass.cpp | 3 +
.../reverse.iter.nav/minus.pass.cpp | 3 +
.../reverse.iter.nav/plus.pass.cpp | 3 +
.../reverse.iter.nav/postdecrement.pass.cpp | 3 +
.../reverse.iter.nav/postincrement.pass.cpp | 3 +
.../reverse.iter.nav/predecrement.pass.cpp | 3 +
.../reverse.iter.nav/preincrement.pass.cpp | 3 +
.../make_reverse_iterator.pass.cpp | 20 +++--
.../reverse.iter.nonmember/minus.pass.cpp | 75 ++++++++++++-------
.../reverse.iter.nonmember/plus.pass.cpp | 3 +
26 files changed, 213 insertions(+), 40 deletions(-)
diff --git a/libcxx/include/__iterator/reverse_iterator.h b/libcxx/include/__iterator/reverse_iterator.h
index 50c0f21eaa286b..5e88d86ad5e9b2 100644
--- a/libcxx/include/__iterator/reverse_iterator.h
+++ b/libcxx/include/__iterator/reverse_iterator.h
@@ -136,10 +136,12 @@ class _LIBCPP_TEMPLATE_VIS reverse_iterator
_LIBCPP_HIDE_FROM_ABI constexpr pointer operator->() const
requires is_pointer_v<_Iter> || requires(const _Iter __i) { __i.operator->(); }
{
+ _Iter __tmp = current;
+ --__tmp;
if constexpr (is_pointer_v<_Iter>) {
- return std::prev(current);
+ return __tmp;
} else {
- return std::prev(current).operator->();
+ return __tmp.operator->();
}
}
#else
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/equal.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/equal.pass.cpp
index fcf8d88fcf62be..b5cb1324a59248 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/equal.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/equal.pass.cpp
@@ -33,6 +33,10 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1), false);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), true);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), false);
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), true);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), false);
+#endif
test(s, s, true);
test(s, s+1, false);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater-equal.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater-equal.pass.cpp
index fdcd02abb0d8ed..3c37dce13dc6af 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater-equal.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater-equal.pass.cpp
@@ -32,6 +32,11 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), true);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), true);
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), false);
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), true);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), true);
+ test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s), false);
+#endif
test(s, s, true);
test(s, s+1, true);
test(s+1, s, false);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater.pass.cpp
index dce331e519646f..288691b7147757 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater.pass.cpp
@@ -32,6 +32,11 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), false);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), true);
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), false);
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), false);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), true);
+ test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s), false);
+#endif
test(s, s, false);
test(s, s+1, true);
test(s+1, s, false);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less-equal.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less-equal.pass.cpp
index e9cea6250a7645..f7babf1ff48d20 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less-equal.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less-equal.pass.cpp
@@ -32,6 +32,11 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), true);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), false);
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), true);
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), true);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), false);
+ test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s), true);
+#endif
test(s, s, true);
test(s, s+1, false);
test(s+1, s, true);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less.pass.cpp
index b66147cf3a03c3..6f3d82c23430fb 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less.pass.cpp
@@ -32,6 +32,11 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), false);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), false);
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), true);
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), false);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), false);
+ test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s), true);
+#endif
test(s, s, false);
test(s, s+1, false);
test(s+1, s, true);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/not-equal.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/not-equal.pass.cpp
index 37a6ff1302ce77..1b921ace4a67f0 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/not-equal.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/not-equal.pass.cpp
@@ -33,6 +33,10 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1), true);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), false);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), true);
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), false);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), true);
+#endif
test(s, s, false);
test(s, s+1, true);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp
index 0e5123a49e2b56..f9d2efa7c2a8cc 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/assign.pass.cpp
@@ -59,6 +59,9 @@ TEST_CONSTEXPR_CXX17 bool tests() {
Derived d;
test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d));
test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d));
+#if TEST_STD_VER >= 20
+ test<cpp20_random_access_iterator<const Base*> >(cpp20_random_access_iterator<Derived*>(&d));
+#endif
test<Base*>(&d);
char c = '\0';
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.default.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.default.pass.cpp
index fcb96de91d1a02..90047b19f5a63a 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.default.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.default.pass.cpp
@@ -26,6 +26,9 @@ TEST_CONSTEXPR_CXX17 void test() {
TEST_CONSTEXPR_CXX17 bool tests() {
test<bidirectional_iterator<const char*> >();
test<random_access_iterator<char*> >();
+#if TEST_STD_VER >= 20
+ test<cpp20_random_access_iterator<char*> >();
+#endif
test<char*>();
test<const char*>();
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.iter.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.iter.pass.cpp
index 801b2cf879ce5b..72e77b08564219 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.iter.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.iter.pass.cpp
@@ -28,6 +28,9 @@ TEST_CONSTEXPR_CXX17 bool tests() {
const char s[] = "123";
test(bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s));
+#endif
test(s);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp
index 8f315e83f6d7b4..fa967b45b1d9f8 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cons/ctor.reverse_iterator.pass.cpp
@@ -33,6 +33,9 @@ TEST_CONSTEXPR_CXX17 bool tests() {
Derived d;
test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d));
test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d));
+#if TEST_STD_VER >= 20
+ test<cpp20_random_access_iterator<const Base*> >(cpp20_random_access_iterator<Derived*>(&d));
+#endif
test<Base*>(&d);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.conv/base.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.conv/base.pass.cpp
index 4fb33f54260457..ded372a32b0b3a 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.conv/base.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.conv/base.pass.cpp
@@ -18,20 +18,28 @@
#include "test_macros.h"
#include "test_iterators.h"
-TEST_CONSTEXPR_CXX17 bool test() {
- typedef bidirectional_iterator<int*> Iter;
+template <class Iter>
+TEST_CONSTEXPR_CXX17 void test() {
int i = 0;
Iter iter(&i);
std::reverse_iterator<Iter> const reverse(iter);
- std::reverse_iterator<Iter>::iterator_type base = reverse.base();
+ typename std::reverse_iterator<Iter>::iterator_type base = reverse.base();
assert(base == Iter(&i));
+}
+
+TEST_CONSTEXPR_CXX17 bool tests() {
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
+#if TEST_STD_VER >= 20
+ test<cpp20_random_access_iterator<int*>>();
+#endif
return true;
}
int main(int, char**) {
- test();
+ tests();
#if TEST_STD_VER > 14
- static_assert(test(), "");
+ static_assert(tests(), "");
#endif
return 0;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/arrow.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/arrow.pass.cpp
index 15d18d9145ef0c..ac862ef1a2492c 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/arrow.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/arrow.pass.cpp
@@ -24,6 +24,54 @@
#include "test_macros.h"
+#if TEST_STD_VER >= 20
+template <class It>
+class cpp20_bidirectional_iterator_with_arrow {
+ It it_;
+
+public:
+ using iterator_category = std::input_iterator_tag;
+ using iterator_concept = std::bidirectional_iterator_tag;
+ using value_type = std::iterator_traits<It>::value_type;
+ using difference_type = std::iterator_traits<It>::difference_type;
+
+ cpp20_bidirectional_iterator_with_arrow() : it_() {}
+ explicit cpp20_bidirectional_iterator_with_arrow(It it) : it_(it) {}
+
+ decltype(auto) operator*() const { return *it_; }
+
+ auto operator->() const {
+ if constexpr (std::is_pointer_v<It>) {
+ return it_;
+ } else {
+ return it_.operator->();
+ }
+ }
+
+ cpp20_bidirectional_iterator_with_arrow& operator++() {
+ ++it_;
+ return *this;
+ }
+ cpp20_bidirectional_iterator_with_arrow& operator--() {
+ --it_;
+ return *this;
+ }
+ cpp20_bidirectional_iterator_with_arrow operator++(int) { return cpp20_bidirectional_iterator_with_arrow(it_++); }
+ cpp20_bidirectional_iterator_with_arrow operator--(int) { return cpp20_bidirectional_iterator_with_arrow(it_--); }
+
+ friend bool
+ operator==(const cpp20_bidirectional_iterator_with_arrow& x, const cpp20_bidirectional_iterator_with_arrow& y) {
+ return x.it_ == y.it_;
+ }
+ friend bool
+ operator!=(const cpp20_bidirectional_iterator_with_arrow& x, const cpp20_bidirectional_iterator_with_arrow& y) {
+ return x.it_ != y.it_;
+ }
+
+ friend It base(const cpp20_bidirectional_iterator_with_arrow& i) { return i.it_; }
+};
+#endif
+
class A
{
int data_;
@@ -113,6 +161,16 @@ int main(int, char**)
static_assert(it1->get() == gC.get(), "");
}
+#endif
+#if TEST_STD_VER >= 20
+ {
+ // The underlying iterator models c++20 bidirectional_iterator,
+ // but does not satisfy c++17 BidirectionalIterator named requirement
+ B data[] = {1, 2, 3};
+ cpp20_bidirectional_iterator_with_arrow<B*> iter(data + 3);
+ auto ri = std::make_reverse_iterator(iter);
+ assert(ri->get() == 3);
+ }
#endif
{
((void)gC);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/bracket.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/bracket.pass.cpp
index 37a857ceefa83d..59bea3a6235ba4 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/bracket.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/bracket.pass.cpp
@@ -33,6 +33,10 @@ TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 4, '1');
test(random_access_iterator<const char*>(s+5), 0, '5');
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+5), 4, '1');
+ test(cpp20_random_access_iterator<const char*>(s+5), 0, '5');
+#endif
test(s+5, 4, '1');
test(s+5, 0, '5');
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp
index 292c6da9a7733e..f568a918a6a835 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp
@@ -21,6 +21,7 @@
#include <cassert>
#include "test_macros.h"
+#include "test_iterators.h"
class A
{
@@ -47,6 +48,10 @@ int main(int, char**)
{
A a;
test(&a+1, A());
+ test(random_access_iterator<A*>(&a+1), A());
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<A*>(&a+1), A());
+#endif
#if TEST_STD_VER > 14
{
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/decrement-assign.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/decrement-assign.pass.cpp
index 8c83ec1e9389f9..dd5fd2c88645ad 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/decrement-assign.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/decrement-assign.pass.cpp
@@ -30,6 +30,9 @@ TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::differen
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s+10));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s+10));
+#endif
test(s+5, 5, s+10);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/increment-assign.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/increment-assign.pass.cpp
index e32fac9fc24fe1..74ab3f96189233 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/increment-assign.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/increment-assign.pass.cpp
@@ -30,6 +30,9 @@ TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::differen
TEST_CONSTEXPR_CXX17 bool tests() {
char const* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s));
+#endif
test(s+5, 5, s);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/minus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/minus.pass.cpp
index f2474dd7669f2c..816c11c65d2c48 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/minus.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/minus.pass.cpp
@@ -29,6 +29,9 @@ TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::differen
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s+10));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s+10));
+#endif
test(s+5, 5, s+10);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/plus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/plus.pass.cpp
index 5673425e796757..72640cd0ec80c3 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/plus.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/plus.pass.cpp
@@ -29,6 +29,9 @@ TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::differen
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s));
+#endif
test(s+5, 5, s);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postdecrement.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postdecrement.pass.cpp
index 24bedad314b7e8..746fa38e60260f 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postdecrement.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postdecrement.pass.cpp
@@ -30,6 +30,9 @@ TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "123";
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s+2));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s+2));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s+2));
+#endif
test(s+1, s+2);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postincrement.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postincrement.pass.cpp
index e15bfb2fd15096..ac95a8a2bbe502 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postincrement.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postincrement.pass.cpp
@@ -30,6 +30,9 @@ TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "123";
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s));
+#endif
test(s+1, s);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/predecrement.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/predecrement.pass.cpp
index 2fbd530a085dcc..6611bca7ec32a1 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/predecrement.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/predecrement.pass.cpp
@@ -30,6 +30,9 @@ TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "123";
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s+2));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s+2));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s+2));
+#endif
test(s+1, s+2);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/preincrement.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/preincrement.pass.cpp
index 5efc8a39e22aa8..195f7ee9800f36 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/preincrement.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/preincrement.pass.cpp
@@ -30,6 +30,9 @@ TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "123";
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s));
+#endif
test(s+1, s);
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/make_reverse_iterator.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/make_reverse_iterator.pass.cpp
index 401eecb2a3b838..fd21eaaab6574d 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/make_reverse_iterator.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/make_reverse_iterator.pass.cpp
@@ -22,17 +22,27 @@
#include "test_iterators.h"
template <class It>
-TEST_CONSTEXPR_CXX17 void test(It i) {
+TEST_CONSTEXPR_CXX17 void test_one(It i) {
const std::reverse_iterator<It> r = std::make_reverse_iterator(i);
assert(r.base() == i);
}
-TEST_CONSTEXPR_CXX17 bool tests() {
+template <class It>
+TEST_CONSTEXPR_CXX17 void test() {
const char* s = "1234567890";
- random_access_iterator<const char*> b(s);
- random_access_iterator<const char*> e(s+10);
+ It b(s);
+ It e(s+10);
while (b != e)
- test (b++);
+ test_one (b++);
+}
+
+TEST_CONSTEXPR_CXX17 bool tests() {
+ test<const char*>();
+ test<bidirectional_iterator<const char*>>();
+ test<random_access_iterator<const char*>>();
+#if TEST_STD_VER >= 20
+ test<cpp20_random_access_iterator<const char*>>();
+#endif
return true;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp
index f7f74d145d73c6..3c25a263d420ab 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp
@@ -23,45 +23,64 @@
#include "test_macros.h"
#include "test_iterators.h"
-template <class, class, class = void> struct HasMinus : std::false_type {};
-template <class R1, class R2> struct HasMinus<R1, R2, decltype((R1() - R2(), void()))> : std::true_type {};
+template <class, class, class = void>
+struct HasMinus : std::false_type {};
+template <class R1, class R2>
+struct HasMinus<R1, R2, decltype((R1() - R2(), void()))> : std::true_type {};
+
+// Test non-subtractable base iterator types
+static_assert(HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<int*> >::value, "");
+static_assert(HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<const int*> >::value, "");
+
+#if TEST_STD_VER >= 11
+static_assert(!HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<char*> >::value, "");
+static_assert(!HasMinus<std::reverse_iterator<bidirectional_iterator<int*> >,
+ std::reverse_iterator<bidirectional_iterator<int*> > >::value,
+ "");
+#endif
template <class It1, class It2>
-TEST_CONSTEXPR_CXX17 void test(It1 l, It2 r, std::ptrdiff_t x) {
- const std::reverse_iterator<It1> r1(l);
- const std::reverse_iterator<It2> r2(r);
- assert((r1 - r2) == x);
+TEST_CONSTEXPR_CXX17 void test_one(It1 l, It2 r, std::ptrdiff_t x) {
+ const std::reverse_iterator<It1> r1(l);
+ const std::reverse_iterator<It2> r2(r);
+ assert((r1 - r2) == x);
}
-TEST_CONSTEXPR_CXX17 bool tests() {
- using PC = const char*;
- char s[3] = {0};
-
- // Test same base iterator type
- test(s, s, 0);
- test(s, s+1, 1);
- test(s+1, s, -1);
+template <class Iter>
+TEST_CONSTEXPR_CXX17 void test() {
+ // Test same base iterator type
+ using PC = const char*;
+ char s[3] = {0};
- // Test different (but subtractable) base iterator types
- test(PC(s), s, 0);
- test(PC(s), s+1, 1);
- test(PC(s+1), s, -1);
+ test_one(Iter(s), Iter(s), 0);
+ test_one(Iter(s), Iter(s + 1), 1);
+ test_one(Iter(s + 1), Iter(s), -1);
+}
- // Test non-subtractable base iterator types
- static_assert( HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<int*> >::value, "");
- static_assert( HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<const int*> >::value, "");
-#if TEST_STD_VER >= 11
- static_assert(!HasMinus<std::reverse_iterator<int*>, std::reverse_iterator<char*> >::value, "");
- static_assert(!HasMinus<std::reverse_iterator<bidirectional_iterator<int*> >, std::reverse_iterator<bidirectional_iterator<int*> > >::value, "");
+TEST_CONSTEXPR_CXX17 bool tests() {
+ {
+ test<char*>();
+ test<random_access_iterator<char*> >();
+#if TEST_STD_VER >= 20
+ test<cpp20_random_access_iterator<char*>>();
#endif
+ }
+ {
+ // Test different (but subtractable) base iterator types
+ using PC = const char*;
+ char s[3] = {0};
+ test_one(PC(s), s, 0);
+ test_one(PC(s), s + 1, 1);
+ test_one(PC(s + 1), s, -1);
+ }
- return true;
+ return true;
}
int main(int, char**) {
- tests();
+ tests();
#if TEST_STD_VER > 14
- static_assert(tests(), "");
+ static_assert(tests(), "");
#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp
index aeb9f89dd48725..06a22c74c49d83 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp
@@ -29,6 +29,9 @@ TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::differen
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
+#if TEST_STD_VER >= 20
+ test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s));
+#endif
test(s+5, 5, s);
return true;
}
>From 5dbd96d1b5b9cef02196401e2bb2ae1039e7b642 Mon Sep 17 00:00:00 2001
From: Hui <hui.xie0621 at gmail.com>
Date: Sun, 13 Oct 2024 10:55:29 +0100
Subject: [PATCH 2/2] CI
---
.../reverse.iter.cmp/equal.pass.cpp | 2 +-
.../reverse.iter.cmp/greater-equal.pass.cpp | 4 +--
.../reverse.iter.cmp/greater.pass.cpp | 4 +--
.../reverse.iter.cmp/less-equal.pass.cpp | 4 +--
.../reverse.iter.cmp/less.pass.cpp | 4 +--
.../reverse.iter.cmp/not-equal.pass.cpp | 2 +-
.../reverse.iter.conv/base.pass.cpp | 24 +++++++--------
.../reverse.iter.elem/arrow.pass.cpp | 4 +--
.../reverse.iter.elem/bracket.pass.cpp | 4 +--
.../reverse.iter.elem/dereference.pass.cpp | 4 +--
.../decrement-assign.pass.cpp | 2 +-
.../increment-assign.pass.cpp | 4 +--
.../reverse.iter.nav/minus.pass.cpp | 4 +--
.../reverse.iter.nav/plus.pass.cpp | 4 +--
.../reverse.iter.nav/postdecrement.pass.cpp | 2 +-
.../reverse.iter.nav/postincrement.pass.cpp | 2 +-
.../reverse.iter.nav/predecrement.pass.cpp | 2 +-
.../reverse.iter.nav/preincrement.pass.cpp | 2 +-
.../make_reverse_iterator.pass.cpp | 30 +++++++++----------
.../reverse.iter.nonmember/minus.pass.cpp | 1 -
.../reverse.iter.nonmember/plus.pass.cpp | 2 +-
21 files changed, 55 insertions(+), 56 deletions(-)
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/equal.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/equal.pass.cpp
index b5cb1324a59248..6fe575ebdd9a0d 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/equal.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/equal.pass.cpp
@@ -35,7 +35,7 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), false);
#if TEST_STD_VER >= 20
test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), true);
- test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), false);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s + 1), false);
#endif
test(s, s, true);
test(s, s+1, false);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater-equal.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater-equal.pass.cpp
index 3c37dce13dc6af..b2bfdb56d646ed 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater-equal.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater-equal.pass.cpp
@@ -34,8 +34,8 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), false);
#if TEST_STD_VER >= 20
test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), true);
- test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), true);
- test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s), false);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s + 1), true);
+ test(cpp20_random_access_iterator<const char*>(s + 1), cpp20_random_access_iterator<const char*>(s), false);
#endif
test(s, s, true);
test(s, s+1, true);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater.pass.cpp
index 288691b7147757..38f9258de31f5e 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/greater.pass.cpp
@@ -34,8 +34,8 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), false);
#if TEST_STD_VER >= 20
test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), false);
- test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), true);
- test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s), false);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s + 1), true);
+ test(cpp20_random_access_iterator<const char*>(s + 1), cpp20_random_access_iterator<const char*>(s), false);
#endif
test(s, s, false);
test(s, s+1, true);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less-equal.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less-equal.pass.cpp
index f7babf1ff48d20..a57930b111314d 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less-equal.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less-equal.pass.cpp
@@ -34,8 +34,8 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), true);
#if TEST_STD_VER >= 20
test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), true);
- test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), false);
- test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s), true);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s + 1), false);
+ test(cpp20_random_access_iterator<const char*>(s + 1), cpp20_random_access_iterator<const char*>(s), true);
#endif
test(s, s, true);
test(s, s+1, false);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less.pass.cpp
index 6f3d82c23430fb..4cd3f249d033e1 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/less.pass.cpp
@@ -34,8 +34,8 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), true);
#if TEST_STD_VER >= 20
test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), false);
- test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), false);
- test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s), true);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s + 1), false);
+ test(cpp20_random_access_iterator<const char*>(s + 1), cpp20_random_access_iterator<const char*>(s), true);
#endif
test(s, s, false);
test(s, s+1, false);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/not-equal.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/not-equal.pass.cpp
index 1b921ace4a67f0..509ac297c3cba6 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/not-equal.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.cmp/not-equal.pass.cpp
@@ -35,7 +35,7 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), true);
#if TEST_STD_VER >= 20
test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s), false);
- test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s+1), true);
+ test(cpp20_random_access_iterator<const char*>(s), cpp20_random_access_iterator<const char*>(s + 1), true);
#endif
test(s, s, false);
test(s, s+1, true);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.conv/base.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.conv/base.pass.cpp
index ded372a32b0b3a..35ed17583c8555 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.conv/base.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.conv/base.pass.cpp
@@ -20,26 +20,26 @@
template <class Iter>
TEST_CONSTEXPR_CXX17 void test() {
- int i = 0;
- Iter iter(&i);
- std::reverse_iterator<Iter> const reverse(iter);
- typename std::reverse_iterator<Iter>::iterator_type base = reverse.base();
- assert(base == Iter(&i));
+ int i = 0;
+ Iter iter(&i);
+ std::reverse_iterator<Iter> const reverse(iter);
+ typename std::reverse_iterator<Iter>::iterator_type base = reverse.base();
+ assert(base == Iter(&i));
}
TEST_CONSTEXPR_CXX17 bool tests() {
- test<bidirectional_iterator<int*> >();
- test<random_access_iterator<int*> >();
+ test<bidirectional_iterator<int*> >();
+ test<random_access_iterator<int*> >();
#if TEST_STD_VER >= 20
- test<cpp20_random_access_iterator<int*>>();
+ test<cpp20_random_access_iterator<int*>>();
#endif
- return true;
+ return true;
}
int main(int, char**) {
- tests();
+ tests();
#if TEST_STD_VER > 14
- static_assert(tests(), "");
+ static_assert(tests(), "");
#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/arrow.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/arrow.pass.cpp
index ac862ef1a2492c..4e11f68dc790cd 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/arrow.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/arrow.pass.cpp
@@ -31,7 +31,7 @@ class cpp20_bidirectional_iterator_with_arrow {
public:
using iterator_category = std::input_iterator_tag;
- using iterator_concept = std::bidirectional_iterator_tag;
+ using iterator_concept = std::bidirectional_iterator_tag;
using value_type = std::iterator_traits<It>::value_type;
using difference_type = std::iterator_traits<It>::difference_type;
@@ -68,7 +68,7 @@ class cpp20_bidirectional_iterator_with_arrow {
return x.it_ != y.it_;
}
- friend It base(const cpp20_bidirectional_iterator_with_arrow& i) { return i.it_; }
+ friend It base(const cpp20_bidirectional_iterator_with_arrow& i) { return i.it_; }
};
#endif
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/bracket.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/bracket.pass.cpp
index 59bea3a6235ba4..8b45bfa09b4fe7 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/bracket.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/bracket.pass.cpp
@@ -34,8 +34,8 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(random_access_iterator<const char*>(s+5), 4, '1');
test(random_access_iterator<const char*>(s+5), 0, '5');
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+5), 4, '1');
- test(cpp20_random_access_iterator<const char*>(s+5), 0, '5');
+ test(cpp20_random_access_iterator<const char*>(s + 5), 4, '1');
+ test(cpp20_random_access_iterator<const char*>(s + 5), 0, '5');
#endif
test(s+5, 4, '1');
test(s+5, 0, '5');
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp
index f568a918a6a835..c3a489085c68b0 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.elem/dereference.pass.cpp
@@ -48,9 +48,9 @@ int main(int, char**)
{
A a;
test(&a+1, A());
- test(random_access_iterator<A*>(&a+1), A());
+ test(random_access_iterator<A*>(&a + 1), A());
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<A*>(&a+1), A());
+ test(cpp20_random_access_iterator<A*>(&a + 1), A());
#endif
#if TEST_STD_VER > 14
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/decrement-assign.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/decrement-assign.pass.cpp
index dd5fd2c88645ad..91c2d9363619bf 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/decrement-assign.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/decrement-assign.pass.cpp
@@ -31,7 +31,7 @@ TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s+10));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s+10));
+ test(cpp20_random_access_iterator<const char*>(s + 5), 5, cpp20_random_access_iterator<const char*>(s + 10));
#endif
test(s+5, 5, s+10);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/increment-assign.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/increment-assign.pass.cpp
index 74ab3f96189233..2a2746f2cc52bd 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/increment-assign.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/increment-assign.pass.cpp
@@ -29,9 +29,9 @@ TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::differen
TEST_CONSTEXPR_CXX17 bool tests() {
char const* s = "1234567890";
- test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
+ test(random_access_iterator<const char*>(s + 5), 5, random_access_iterator<const char*>(s));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s));
+ test(cpp20_random_access_iterator<const char*>(s + 5), 5, cpp20_random_access_iterator<const char*>(s));
#endif
test(s+5, 5, s);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/minus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/minus.pass.cpp
index 816c11c65d2c48..759cacad94e24c 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/minus.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/minus.pass.cpp
@@ -28,9 +28,9 @@ TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::differen
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
- test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s+10));
+ test(random_access_iterator<const char*>(s + 5), 5, random_access_iterator<const char*>(s + 10));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s+10));
+ test(cpp20_random_access_iterator<const char*>(s + 5), 5, cpp20_random_access_iterator<const char*>(s + 10));
#endif
test(s+5, 5, s+10);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/plus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/plus.pass.cpp
index 72640cd0ec80c3..24fa84e4f37c8b 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/plus.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/plus.pass.cpp
@@ -28,9 +28,9 @@ TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::differen
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
- test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
+ test(random_access_iterator<const char*>(s + 5), 5, random_access_iterator<const char*>(s));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s));
+ test(cpp20_random_access_iterator<const char*>(s + 5), 5, cpp20_random_access_iterator<const char*>(s));
#endif
test(s+5, 5, s);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postdecrement.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postdecrement.pass.cpp
index 746fa38e60260f..f0551b5efece09 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postdecrement.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postdecrement.pass.cpp
@@ -31,7 +31,7 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s+2));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s+2));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s+2));
+ test(cpp20_random_access_iterator<const char*>(s + 1), cpp20_random_access_iterator<const char*>(s + 2));
#endif
test(s+1, s+2);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postincrement.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postincrement.pass.cpp
index ac95a8a2bbe502..f1d3ea21a5b860 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postincrement.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/postincrement.pass.cpp
@@ -31,7 +31,7 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s));
+ test(cpp20_random_access_iterator<const char*>(s + 1), cpp20_random_access_iterator<const char*>(s));
#endif
test(s+1, s);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/predecrement.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/predecrement.pass.cpp
index 6611bca7ec32a1..5a2ac785703672 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/predecrement.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/predecrement.pass.cpp
@@ -31,7 +31,7 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s+2));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s+2));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s+2));
+ test(cpp20_random_access_iterator<const char*>(s + 1), cpp20_random_access_iterator<const char*>(s + 2));
#endif
test(s+1, s+2);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/preincrement.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/preincrement.pass.cpp
index 195f7ee9800f36..6087eedd2449f2 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/preincrement.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nav/preincrement.pass.cpp
@@ -31,7 +31,7 @@ TEST_CONSTEXPR_CXX17 bool tests() {
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+1), cpp20_random_access_iterator<const char*>(s));
+ test(cpp20_random_access_iterator<const char*>(s + 1), cpp20_random_access_iterator<const char*>(s));
#endif
test(s+1, s);
return true;
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/make_reverse_iterator.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/make_reverse_iterator.pass.cpp
index fd21eaaab6574d..4a4e474a550835 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/make_reverse_iterator.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/make_reverse_iterator.pass.cpp
@@ -23,33 +23,33 @@
template <class It>
TEST_CONSTEXPR_CXX17 void test_one(It i) {
- const std::reverse_iterator<It> r = std::make_reverse_iterator(i);
- assert(r.base() == i);
+ const std::reverse_iterator<It> r = std::make_reverse_iterator(i);
+ assert(r.base() == i);
}
template <class It>
TEST_CONSTEXPR_CXX17 void test() {
- const char* s = "1234567890";
- It b(s);
- It e(s+10);
- while (b != e)
- test_one (b++);
+ const char* s = "1234567890";
+ It b(s);
+ It e(s + 10);
+ while (b != e)
+ test_one(b++);
}
TEST_CONSTEXPR_CXX17 bool tests() {
- test<const char*>();
- test<bidirectional_iterator<const char*>>();
- test<random_access_iterator<const char*>>();
+ test<const char*>();
+ test<bidirectional_iterator<const char*>>();
+ test<random_access_iterator<const char*>>();
#if TEST_STD_VER >= 20
- test<cpp20_random_access_iterator<const char*>>();
+ test<cpp20_random_access_iterator<const char*>>();
#endif
- return true;
+ return true;
}
int main(int, char**) {
- tests();
+ tests();
#if TEST_STD_VER > 14
- static_assert(tests(), "");
+ static_assert(tests(), "");
#endif
- return 0;
+ return 0;
}
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp
index 3c25a263d420ab..676f6e1b491695 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/minus.pass.cpp
@@ -49,7 +49,6 @@ TEST_CONSTEXPR_CXX17 void test_one(It1 l, It2 r, std::ptrdiff_t x) {
template <class Iter>
TEST_CONSTEXPR_CXX17 void test() {
// Test same base iterator type
- using PC = const char*;
char s[3] = {0};
test_one(Iter(s), Iter(s), 0);
diff --git a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp
index 06a22c74c49d83..9ead123781bc86 100644
--- a/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp
+++ b/libcxx/test/std/iterators/predef.iterators/reverse.iterators/reverse.iter.nonmember/plus.pass.cpp
@@ -30,7 +30,7 @@ TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
#if TEST_STD_VER >= 20
- test(cpp20_random_access_iterator<const char*>(s+5), 5, cpp20_random_access_iterator<const char*>(s));
+ test(cpp20_random_access_iterator<const char*>(s + 5), 5, cpp20_random_access_iterator<const char*>(s));
#endif
test(s+5, 5, s);
return true;
More information about the libcxx-commits
mailing list