[libcxx-commits] [libcxx] 9f967ee - [libc++] NFC: More refactoring in the prev/next/advance tests per review comments

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 14 05:42:53 PDT 2021


Author: Louis Dionne
Date: 2021-06-14T08:42:44-04:00
New Revision: 9f967eed89e66e39909c59ec0246dc2877d75f51

URL: https://github.com/llvm/llvm-project/commit/9f967eed89e66e39909c59ec0246dc2877d75f51
DIFF: https://github.com/llvm/llvm-project/commit/9f967eed89e66e39909c59ec0246dc2877d75f51.diff

LOG: [libc++] NFC: More refactoring in the prev/next/advance tests per review comments

Added: 
    

Modified: 
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp
    libcxx/test/support/test_iterators.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp
index 60fc2a302e7d1..be4d9b61401d0 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp
@@ -24,14 +24,14 @@ static_assert(is_function_like<decltype(std::ranges::advance)>());
 
 using range_t = std::array<int, 10>;
 
-template <std::input_or_output_iterator I>
+template <std::input_or_output_iterator It>
 constexpr void check_move_forward(std::ptr
diff _t const n) {
   auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
-  auto first = stride_counting_iterator(I(range.begin()));
+  auto first = stride_counting_iterator(It(range.begin()));
   std::ranges::advance(first, n);
 
   assert(first.base().base() == range.begin() + n);
-  if constexpr (std::random_access_iterator<I>) {
+  if constexpr (std::random_access_iterator<It>) {
     assert(first.stride_count() == 0 || first.stride_count() == 1);
     assert(first.stride_displacement() == 1);
   } else {
@@ -40,14 +40,14 @@ constexpr void check_move_forward(std::ptr
diff _t const n) {
   }
 }
 
-template <std::bidirectional_iterator I>
+template <std::bidirectional_iterator It>
 constexpr void check_move_backward(std::ptr
diff _t const n) {
   auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
-  auto first = stride_counting_iterator(I(range.begin() + n));
+  auto first = stride_counting_iterator(It(range.begin() + n));
   std::ranges::advance(first, -n);
   assert(first.base().base() == range.begin());
 
-  if constexpr (std::random_access_iterator<I>) {
+  if constexpr (std::random_access_iterator<It>) {
     assert(first.stride_count() == 0 || first.stride_count() == 1);
     assert(first.stride_displacement() == 1);
   } else {
@@ -83,7 +83,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   assert(test());
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
index 128d298b4994c..29af3a1008321 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
@@ -53,14 +53,15 @@ struct expected_t {
   std::ptr
diff _t result;
 };
 
-template <std::input_or_output_iterator I>
-constexpr void check_forward_sized_sentinel(std::ptr
diff _t const n, expected_t const expected, range_t& range) {
-  auto current = stride_counting_iterator(I(range.begin()));
-  auto const result = std::ranges::advance(current, n, distance_apriori_sentinel(range.size()));
+template <std::input_or_output_iterator It>
+constexpr void check_forward_sized_sentinel(std::ptr
diff _t n, expected_t expected, range_t& range) {
+  using Difference = std::iter_
diff erence_t<It>;
+  auto current = stride_counting_iterator(It(range.begin()));
+  Difference const result = std::ranges::advance(current, n, distance_apriori_sentinel(range.size()));
   assert(current.base().base() == expected.coordinate);
   assert(result == expected.result);
 
-  if constexpr (std::random_access_iterator<I>) {
+  if constexpr (std::random_access_iterator<It>) {
     assert(current.stride_count() == 0 || current.stride_count() == 1);
     assert(current.stride_displacement() == current.stride_count());
   } else {
@@ -69,10 +70,11 @@ constexpr void check_forward_sized_sentinel(std::ptr
diff _t const n, expected_t c
   }
 }
 
-template <std::random_access_iterator I>
-constexpr void check_backward_sized_sentinel(std::ptr
diff _t const n, expected_t const expected, range_t& range) {
-  auto current = stride_counting_iterator(I(range.end()));
-  auto const result = std::ranges::advance(current, -n, stride_counting_iterator(I(range.begin())));
+template <std::random_access_iterator It>
+constexpr void check_backward_sized_sentinel(std::ptr
diff _t n, expected_t expected, range_t& range) {
+  using Difference = std::iter_
diff erence_t<It>;
+  auto current = stride_counting_iterator(It(range.end()));
+  Difference const result = std::ranges::advance(current, -n, stride_counting_iterator(It(range.begin())));
   assert(current.base().base() == expected.coordinate);
   assert(result == expected.result);
 
@@ -80,19 +82,21 @@ constexpr void check_backward_sized_sentinel(std::ptr
diff _t const n, expected_t
   assert(current.stride_displacement() == current.stride_count());
 }
 
-template <std::input_or_output_iterator I>
-constexpr void check_forward(std::ptr
diff _t const n, expected_t const expected, range_t& range) {
-  auto current = stride_counting_iterator(I(range.begin()));
-  auto const result = std::ranges::advance(current, n, sentinel_wrapper(I(range.end())));
+template <std::input_or_output_iterator It>
+constexpr void check_forward(std::ptr
diff _t n, expected_t expected, range_t& range) {
+  using Difference = std::iter_
diff erence_t<It>;
+  auto current = stride_counting_iterator(It(range.begin()));
+  Difference const result = std::ranges::advance(current, n, sentinel_wrapper(It(range.end())));
   assert(current.base().base() == expected.coordinate);
   assert(result == expected.result);
   assert(current.stride_count() == n - result);
 }
 
-template <std::bidirectional_iterator I>
-constexpr void check_backward(std::ptr
diff _t const n, expected_t const expected, range_t& range) {
-  auto current = stride_counting_iterator(I(range.end()));
-  auto const result = std::ranges::advance(current, -n, stride_counting_iterator(I(range.begin())));
+template <std::bidirectional_iterator It>
+constexpr void check_backward(std::ptr
diff _t n, expected_t expected, range_t& range) {
+  using Difference = std::iter_
diff erence_t<It>;
+  auto current = stride_counting_iterator(It(range.end()));
+  Difference const result = std::ranges::advance(current, -n, stride_counting_iterator(It(range.begin())));
   assert(current.base().base() == expected.coordinate);
   assert(result == expected.result);
   assert(current.stride_count() == n + result);
@@ -139,7 +143,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   assert(test());
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp
index 1a740665f0c66..902e7d2b5d580 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp
@@ -48,23 +48,23 @@ class distance_apriori_sentinel {
   std::ptr
diff _t count_ = 0;
 };
 
-template <std::input_or_output_iterator I, std::sentinel_for<I> S = I>
+template <std::input_or_output_iterator It, std::sentinel_for<It> Sent = It>
 constexpr void check_assignable_case(std::ptr
diff _t const n) {
   auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
-  auto first = stride_counting_iterator(I(range.begin()));
-  std::ranges::advance(first, stride_counting_iterator(S(I(range.begin() + n))));
+  auto first = stride_counting_iterator(It(range.begin()));
+  std::ranges::advance(first, stride_counting_iterator(Sent(It(range.begin() + n))));
   assert(first.base().base() == range.begin() + n);
   assert(first.stride_count() == 0); // because we got here by assigning from last, not by incrementing
 }
 
-template <std::input_or_output_iterator I>
+template <std::input_or_output_iterator It>
 constexpr void check_sized_sentinel_case(std::ptr
diff _t const n) {
   auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
-  auto first = stride_counting_iterator(I(range.begin()));
+  auto first = stride_counting_iterator(It(range.begin()));
   std::ranges::advance(first, distance_apriori_sentinel(n));
 
   assert(first.base().base() == range.begin() + n);
-  if constexpr (std::random_access_iterator<I>) {
+  if constexpr (std::random_access_iterator<It>) {
     assert(first.stride_count() == 1);
     assert(first.stride_displacement() == 1);
   } else {
@@ -73,11 +73,11 @@ constexpr void check_sized_sentinel_case(std::ptr
diff _t const n) {
   }
 }
 
-template <std::input_or_output_iterator I>
+template <std::input_or_output_iterator It>
 constexpr void check_sentinel_case(std::ptr
diff _t const n) {
   auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
-  auto first = stride_counting_iterator(I(range.begin()));
-  auto const last = I(range.begin() + n);
+  auto first = stride_counting_iterator(It(range.begin()));
+  auto const last = It(range.begin() + n);
   std::ranges::advance(first, sentinel_wrapper(last));
   assert(first.base() == last);
   assert(first.stride_count() == n);
@@ -107,7 +107,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   assert(test());
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp
index 8c65059a66b79..19379e3f15259 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp
@@ -18,9 +18,10 @@
 #include <cstddef>
 #include <memory>
 #include <utility>
+#include "test_iterators.h"
 
 template <class ...Args>
-concept has_ranges_next = requires (Args ...args) {
+concept has_ranges_next = requires (Args&& ...args) {
   { std::ranges::next(std::forward<Args>(args)...) };
 };
 
@@ -31,4 +32,7 @@ static_assert(!has_ranges_next<It, It>);
 static_assert(!has_ranges_next<It, std::ptr
diff _t, It>);
 
 // Test the test
-static_assert(has_ranges_next<int*, std::ptr
diff _t, int*>);
+using It2 = forward_iterator<int*>;
+static_assert(has_ranges_next<It2>);
+static_assert(has_ranges_next<It2, std::ptr
diff _t>);
+static_assert(has_ranges_next<It2, std::ptr
diff _t, It2>);

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp
index 5e69ffd723fec..4f74e85f67d73 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp
@@ -40,7 +40,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   test();
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp
index 01217704ca100..9e5bc7300478c 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp
@@ -19,19 +19,19 @@
 
 #include "test_iterators.h"
 
-template <std::input_or_output_iterator I>
-constexpr void check_steps(I it, std::ptr
diff _t n, int const* expected) {
+template <std::input_or_output_iterator It>
+constexpr void check_steps(It it, std::ptr
diff _t n, int const* expected) {
   {
-    auto result = std::ranges::next(std::move(it), n);
+    It result = std::ranges::next(std::move(it), n);
     assert(&*result == expected);
   }
 
   // Count the number of operations
   {
     stride_counting_iterator strided_it(std::move(it));
-    auto result = std::ranges::next(std::move(strided_it), n);
+    stride_counting_iterator result = std::ranges::next(std::move(strided_it), n);
     assert(&*result == expected);
-    if constexpr (std::random_access_iterator<I>) {
+    if constexpr (std::random_access_iterator<It>) {
       assert(result.stride_count() == 1); // uses += exactly once
       assert(result.stride_displacement() == 1);
     } else {
@@ -68,7 +68,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   test();
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp
index 6da7149ce38da..29067c8eab44e 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp
@@ -17,26 +17,27 @@
 
 #include "test_iterators.h"
 
-template <std::input_or_output_iterator I>
-constexpr void check(I it, std::ptr
diff _t n, I last) {
+template <std::input_or_output_iterator It>
+constexpr void check(It it, std::ptr
diff _t n, It last) {
   {
-    auto result = std::ranges::next(it, n, last);
+    It result = std::ranges::next(it, n, last);
     assert(result == last);
   }
 
   // Count the number of operations
   {
-    stride_counting_iterator strided_it(it), strided_last(last);
-    auto result = std::ranges::next(strided_it, n, strided_last);
+    stride_counting_iterator<It> strided_it(it);
+    stride_counting_iterator<It> strided_last(last);
+    stride_counting_iterator<It> result = std::ranges::next(strided_it, n, strided_last);
     assert(result == strided_last);
-    if constexpr (std::random_access_iterator<I>) {
+    if constexpr (std::random_access_iterator<It>) {
       if (n == 0 || n >= (last - it)) {
         assert(result.stride_count() == 0); // uses the assign-from-sentinel codepath
       } else {
         assert(result.stride_count() == 1); // uses += exactly once
       }
     } else {
-      auto const abs_n = n < 0 ? -n : n;
+      std::ptr
diff _t const abs_n = n < 0 ? -n : n;
       assert(result.stride_count() == abs_n);
       assert(result.stride_displacement() == n);
     }
@@ -65,8 +66,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   assert(test());
-
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp
index c33a145d73f24..ef28113dbf7ef 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp
@@ -46,10 +46,10 @@ class distance_apriori_sentinel {
   std::ptr
diff _t count_ = 0;
 };
 
-template <std::input_or_output_iterator I>
-constexpr void check_assignable(I it, I last, int const* expected) {
+template <std::input_or_output_iterator It>
+constexpr void check_assignable(It it, It last, int const* expected) {
   {
-    auto result = std::ranges::next(std::move(it), std::move(last));
+    It result = std::ranges::next(std::move(it), std::move(last));
     assert(&*result == expected);
   }
 
@@ -63,8 +63,8 @@ constexpr void check_assignable(I it, I last, int const* expected) {
   }
 }
 
-template <std::input_or_output_iterator I>
-constexpr void check_sized_sentinel(I it, I last, int const* expected) {
+template <std::input_or_output_iterator It>
+constexpr void check_sized_sentinel(It it, It last, int const* expected) {
   auto n = (last.base() - it.base());
 
   {
@@ -80,7 +80,7 @@ constexpr void check_sized_sentinel(I it, I last, int const* expected) {
     auto result = std::ranges::next(std::move(strided_it), sent);
     assert(&*result == expected);
 
-    if constexpr (std::random_access_iterator<I>) {
+    if constexpr (std::random_access_iterator<It>) {
       assert(result.stride_count() == 1); // should have used exactly one +=
       assert(result.stride_displacement() == 1);
     } else {
@@ -90,13 +90,13 @@ constexpr void check_sized_sentinel(I it, I last, int const* expected) {
   }
 }
 
-template <std::input_or_output_iterator I>
-constexpr void check_sentinel(I it, I last, int const* expected) {
+template <std::input_or_output_iterator It>
+constexpr void check_sentinel(It it, It last, int const* expected) {
   auto n = (last.base() - it.base());
 
   {
     auto sent = sentinel_wrapper(last);
-    auto result = std::ranges::next(std::move(it), sent);
+    It result = std::ranges::next(std::move(it), sent);
     assert(&*result == expected);
   }
 
@@ -104,7 +104,7 @@ constexpr void check_sentinel(I it, I last, int const* expected) {
   {
     auto strided_it = stride_counting_iterator(it);
     auto sent = sentinel_wrapper(stride_counting_iterator(last));
-    auto result = std::ranges::next(std::move(strided_it), sent);
+    stride_counting_iterator result = std::ranges::next(std::move(strided_it), sent);
     assert(&*result == expected);
     assert(result.stride_count() == n); // must have used ++ until it hit the sentinel
   }
@@ -136,7 +136,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   test();
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp
index 78265299340c7..05e49b56db8e1 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp
@@ -20,7 +20,7 @@
 #include "test_iterators.h"
 
 template <class ...Args>
-concept has_ranges_prev = requires (Args ...args) {
+concept has_ranges_prev = requires (Args&& ...args) {
   { std::ranges::prev(std::forward<Args>(args)...) };
 };
 
@@ -30,4 +30,7 @@ static_assert(!has_ranges_prev<It, std::ptr
diff _t>);
 static_assert(!has_ranges_prev<It, std::ptr
diff _t, It>);
 
 // Test the test
-static_assert(has_ranges_prev<int*, std::ptr
diff _t, int*>);
+using It2 = bidirectional_iterator<int*>;
+static_assert(has_ranges_prev<It2>);
+static_assert(has_ranges_prev<It2, std::ptr
diff _t>);
+static_assert(has_ranges_prev<It2, std::ptr
diff _t, It2>);

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp
index 4bc642437224f..a8d6b47dd591d 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp
@@ -20,9 +20,11 @@
 template <class It>
 constexpr void check() {
   int range[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+  assert(std::ranges::prev(It(&range[1])) == It(&range[0]));
   assert(std::ranges::prev(It(&range[4])) == It(&range[3]));
   assert(std::ranges::prev(It(&range[5])) == It(&range[4]));
   assert(std::ranges::prev(It(&range[6])) == It(&range[5]));
+  assert(std::ranges::prev(It(&range[10])) == It(&range[9]));
 }
 
 constexpr bool test() {
@@ -34,7 +36,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   test();
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp
index e8f7beb99ac08..c089bb5d07c4d 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp
@@ -18,17 +18,17 @@
 
 #include "test_iterators.h"
 
-template <std::input_or_output_iterator I>
-constexpr void check(I it, std::ptr
diff _t n, int const* expected) {
-  auto result = std::ranges::prev(stride_counting_iterator(std::move(it)), n);
+template <std::input_or_output_iterator It>
+constexpr void check(It it, std::ptr
diff _t n, int const* expected) {
+  stride_counting_iterator result = std::ranges::prev(stride_counting_iterator(std::move(it)), n);
   assert(result.base().base() == expected);
 
-  if constexpr (std::random_access_iterator<I>) {
+  if constexpr (std::random_access_iterator<It>) {
     assert(result.stride_count() <= 1);
     // we can't say anything about the stride displacement, cause we could be using -= or +=.
   } else {
-    auto const distance = n < 0 ? -n : n;
-    assert(result.stride_count() == distance);
+    std::ptr
diff _t const abs_n = n < 0 ? -n : n;
+    assert(result.stride_count() == abs_n);
     assert(result.stride_displacement() == -n);
   }
 }
@@ -51,7 +51,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   test();
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp
index 5e1734b572a4e..bf61d243ff1b9 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp
@@ -17,21 +17,22 @@
 
 #include "test_iterators.h"
 
-template <std::bidirectional_iterator I>
-constexpr void check(I it, std::ptr
diff _t n, I last) {
+template <std::bidirectional_iterator It>
+constexpr void check(It it, std::ptr
diff _t n, It last) {
   auto abs = [](auto x) { return x < 0 ? -x : x; };
 
   {
-    auto result = std::ranges::prev(it, n, last);
+    It result = std::ranges::prev(it, n, last);
     assert(result == last);
   }
 
   // Count the number of operations
   {
-    stride_counting_iterator strided_it(it), strided_last(last);
-    auto result = std::ranges::prev(strided_it, n, strided_last);
+    stride_counting_iterator<It> strided_it(it);
+    stride_counting_iterator<It> strided_last(last);
+    stride_counting_iterator<It> result = std::ranges::prev(strided_it, n, strided_last);
     assert(result == strided_last);
-    if constexpr (std::random_access_iterator<I>) {
+    if constexpr (std::random_access_iterator<It>) {
       if (n == 0 || abs(n) >= abs(last - it)) {
         assert(result.stride_count() == 0); // uses the assign-from-sentinel codepath
       } else {
@@ -62,8 +63,7 @@ constexpr bool test() {
 }
 
 int main(int, char**) {
-  static_assert(test());
   assert(test());
-
+  static_assert(test());
   return 0;
 }

diff  --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h
index 3ab759358336f..51627178e6d32 100644
--- a/libcxx/test/support/test_iterators.h
+++ b/libcxx/test/support/test_iterators.h
@@ -663,9 +663,9 @@ struct cpp20_input_iterator {
 
   constexpr void operator++(int) { ++base_; }
 
-  [[nodiscard]] constexpr I const& base() const& { return base_; }
+  constexpr I const& base() const& { return base_; }
 
-  [[nodiscard]] constexpr I base() && { return std::move(base_); }
+  constexpr I base() && { return std::move(base_); }
 
 private:
   I base_ = I();


        


More information about the libcxx-commits mailing list