[libcxx-commits] [libcxx] [libc++][test] Fix assumptions that `std::array` iterators are pointers (PR #74430)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 5 00:02:56 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 0ca80eb5e814a6d061556888c9c9fbd04f054a80 e0ee3276150372d8d22860f70f2f5031df7a3c32 -- libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace.pass.cpp libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_copy.pass.cpp libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_copy_if.pass.cpp libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_if.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.merge/pstl.merge.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp libcxx/test/std/containers/from_range_helpers.h libcxx/test/std/containers/views/views.span/span.cons/iterator_sentinel.pass.cpp libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/compare.pass.cpp libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/decrement.pass.cpp libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/deref.pass.cpp libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/increment.pass.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_copy_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_copy_if.pass.cpp
index 89ea1652eb..00b40a4e15 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_copy_if.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_copy_if.pass.cpp
@@ -34,21 +34,36 @@ struct Test {
       std::array a = {1, 2, 3, 4, 5, 6, 7, 8};
       std::array<int, a.size()> out;
       std::replace_copy_if(
-          policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), Iter(std::data(out)), [](int i) { return i == 3; }, 6);
+          policy,
+          Iter(std::data(a)),
+          Iter(std::data(a) + std::size(a)),
+          Iter(std::data(out)),
+          [](int i) { return i == 3; },
+          6);
       assert((out == std::array{1, 2, 6, 4, 5, 6, 7, 8}));
     }
 
     { // empty range works
       std::array<int, 0> a = {};
       std::replace_copy_if(
-          policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), Iter(std::data(a)), [](int i) { return i == 3; }, 6);
+          policy,
+          Iter(std::data(a)),
+          Iter(std::data(a) + std::size(a)),
+          Iter(std::data(a)),
+          [](int i) { return i == 3; },
+          6);
     }
 
     { // non-empty range without a match works
       std::array a = {1, 2};
       std::array<int, a.size()> out;
       std::replace_copy_if(
-          policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), Iter(out.data()), [](int i) { return i == 3; }, 6);
+          policy,
+          Iter(std::data(a)),
+          Iter(std::data(a) + std::size(a)),
+          Iter(out.data()),
+          [](int i) { return i == 3; },
+          6);
       assert((out == std::array{1, 2}));
     }
 
@@ -56,7 +71,12 @@ struct Test {
       std::array a = {3};
       std::array<int, a.size()> out;
       std::replace_copy_if(
-          policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), Iter(std::data(out)), [](int i) { return i == 3; }, 6);
+          policy,
+          Iter(std::data(a)),
+          Iter(std::data(a) + std::size(a)),
+          Iter(std::data(out)),
+          [](int i) { return i == 3; },
+          6);
       assert((out == std::array{6}));
     }
 
@@ -64,7 +84,12 @@ struct Test {
       std::array a = {3, 4};
       std::array<int, a.size()> out;
       std::replace_copy_if(
-          policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), Iter(std::data(out)), [](int i) { return i == 3; }, 6);
+          policy,
+          Iter(std::data(a)),
+          Iter(std::data(a) + std::size(a)),
+          Iter(std::data(out)),
+          [](int i) { return i == 3; },
+          6);
       assert((out == std::array{6, 4}));
     }
 
@@ -72,7 +97,12 @@ struct Test {
       std::array a = {1, 2, 3, 4, 3, 3, 5, 6, 3};
       std::array<int, a.size()> out;
       std::replace_copy_if(
-          policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), Iter(std::data(out)), [](int i) { return i == 3; }, 9);
+          policy,
+          Iter(std::data(a)),
+          Iter(std::data(a) + std::size(a)),
+          Iter(std::data(out)),
+          [](int i) { return i == 3; },
+          9);
       assert((out == std::array{1, 2, 9, 4, 9, 9, 5, 6, 9}));
     }
 
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_if.pass.cpp
index 99ea5e2308..9e4f4d3f03 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_if.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/pstl.replace_if.pass.cpp
@@ -42,7 +42,8 @@ struct Test {
 
     { // non-empty range without a match works
       std::array a = {1, 2};
-      std::replace_if(policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), [](int) { return false; }, 6);
+      std::replace_if(
+          policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), [](int) { return false; }, 6);
     }
 
     { // single element range works
@@ -61,7 +62,8 @@ struct Test {
 
     { // multiple matching elements work
       std::array a = {1, 2, 3, 4, 3, 3, 5, 6, 3};
-      std::replace_if(policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), [](int i) { return i == 3; }, 9);
+      std::replace_if(
+          policy, Iter(std::data(a)), Iter(std::data(a) + std::size(a)), [](int i) { return i == 3; }, 9);
       assert((a == std::array{1, 2, 9, 4, 9, 9, 5, 6, 9}));
     }
 
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/pstl.merge.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/pstl.merge.pass.cpp
index c685bff8f4..ade15ce0b7 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/pstl.merge.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/pstl.merge.pass.cpp
@@ -53,15 +53,23 @@ struct Test {
       std::array<int, 0> a;
       std::array<int, 0> b;
       std::array<int, std::size(a) + std::size(b)> out;
-      std::merge(
-          policy, Iter1(std::data(a)), Iter1(std::data(a) + std::size(a)), Iter2(std::data(b)), Iter2(std::data(b) + std::size(b)), std::begin(out));
+      std::merge(policy,
+                 Iter1(std::data(a)),
+                 Iter1(std::data(a) + std::size(a)),
+                 Iter2(std::data(b)),
+                 Iter2(std::data(b) + std::size(b)),
+                 std::begin(out));
     }
     { // check that it works with the first range being empty
       std::array<int, 0> a;
       int b[] = {2, 4, 6, 8, 10};
       std::array<int, std::size(a) + std::size(b)> out;
-      std::merge(
-          policy, Iter1(std::data(a)), Iter1(std::data(a) + std::size(a)), Iter2(std::begin(b)), Iter2(std::end(b)), std::begin(out));
+      std::merge(policy,
+                 Iter1(std::data(a)),
+                 Iter1(std::data(a) + std::size(a)),
+                 Iter2(std::begin(b)),
+                 Iter2(std::end(b)),
+                 std::begin(out));
       assert((out == std::array{2, 4, 6, 8, 10}));
     }
 
@@ -69,8 +77,12 @@ struct Test {
       int a[] = {2, 4, 6, 8, 10};
       std::array<int, 0> b;
       std::array<int, std::size(a) + std::size(b)> out;
-      std::merge(
-          policy, Iter1(std::begin(a)), Iter1(std::end(a)), Iter2(std::data(b)), Iter2(std::data(b) + std::size(b)), std::begin(out));
+      std::merge(policy,
+                 Iter1(std::begin(a)),
+                 Iter1(std::end(a)),
+                 Iter2(std::data(b)),
+                 Iter2(std::data(b) + std::size(b)),
+                 std::begin(out));
       assert((out == std::array{2, 4, 6, 8, 10}));
     }
 
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp
index 17db46edfb..d7cd499876 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way.pass.cpp
@@ -27,8 +27,8 @@
 
 template <typename Iter1, typename Iter2, typename C1, typename C2, typename Order>
 constexpr void test_lexicographical_compare(C1 a, C2 b, Order expected) {
-  std::same_as<Order> decltype(auto) result =
-      std::lexicographical_compare_three_way(Iter1{a.data()}, Iter1{a.data() + a.size()}, Iter2{b.data()}, Iter2{b.data() + b.size()});
+  std::same_as<Order> decltype(auto) result = std::lexicographical_compare_three_way(
+      Iter1{a.data()}, Iter1{a.data() + a.size()}, Iter2{b.data()}, Iter2{b.data() + b.size()});
   assert(expected == result);
 }
 
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp
index 1f8b18737a..f2f7d538d7 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.three.way/lexicographical_compare_three_way_comp.pass.cpp
@@ -56,8 +56,8 @@ static_assert(has_lexicographical_compare<decltype(compare_int_result)>);
 
 template <typename Iter1, typename Iter2, typename C1, typename C2, typename Order, typename Comparator>
 constexpr void test_lexicographical_compare(C1 a, C2 b, Comparator comp, Order expected) {
-  std::same_as<Order> decltype(auto) result =
-      std::lexicographical_compare_three_way(Iter1{a.data()}, Iter1{a.data() + a.size()}, Iter2{b.data()}, Iter2{b.data() + b.size()}, comp);
+  std::same_as<Order> decltype(auto) result = std::lexicographical_compare_three_way(
+      Iter1{a.data()}, Iter1{a.data() + a.size()}, Iter2{b.data()}, Iter2{b.data() + b.size()}, comp);
   assert(expected == result);
 }
 
diff --git a/libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/decrement.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/decrement.pass.cpp
index a331c794c8..c6c036363d 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/decrement.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/decrement.pass.cpp
@@ -137,8 +137,8 @@ constexpr void test() {
   // Test with a predicate that is invocable but not callable (i.e. cannot be called like regular function 'f()')
   {
     std::array array = {1, 2, 3, -3, -2, -1};
-    auto v = View{Iterator{array.data()}, Sentinel{Iterator{array.data() + array.size()}}}
-           | std::views::transform([](int x) { return IntWrapper{x}; });
+    auto v           = View{Iterator{array.data()}, Sentinel{Iterator{array.data() + array.size()}}} |
+             std::views::transform([](int x) { return IntWrapper{x}; });
     auto view = std::views::chunk_by(std::move(v), &IntWrapper::lessEqual);
 
     auto it = std::ranges::next(view.begin());
diff --git a/libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/increment.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/increment.pass.cpp
index 8a7ff4e385..3a9262cb2a 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/increment.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.chunk.by/range.chunk.by.iter/increment.pass.cpp
@@ -109,8 +109,8 @@ constexpr void test() {
   // Test with a predicate that is invocable but not callable (i.e. cannot be called like regular function 'f()')
   {
     std::array array = {1, 2, 3, -3, -2, -1};
-    auto v = View{Iterator{array.data()}, Sentinel{Iterator{array.data() + array.size()}}}
-           | std::views::transform([](int x) { return IntWrapper{x}; });
+    auto v           = View{Iterator{array.data()}, Sentinel{Iterator{array.data() + array.size()}}} |
+             std::views::transform([](int x) { return IntWrapper{x}; });
     auto view = std::views::chunk_by(std::move(v), &IntWrapper::lessEqual);
 
     auto it = view.begin();

``````````

</details>


https://github.com/llvm/llvm-project/pull/74430


More information about the libcxx-commits mailing list