[libcxx-commits] [libcxx] [libc++][test] Avoid non-Standard zero-length arrays (PR #74183)
Stephan T. Lavavej via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Dec 1 23:28:27 PST 2023
https://github.com/StephanTLavavej updated https://github.com/llvm/llvm-project/pull/74183
>From 4897f1aa31fb928fb2997499153a8907bc7615eb Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Thu, 30 Nov 2023 20:58:04 -0800
Subject: [PATCH 1/2] Avoid non-Standard zero-length arrays.
I'm adding pointers in order to avoid disrupting the following code.
Add `-Wzero-length-array` to `params.py` to prevent future occurrences.
Might need to be clang-formatted.
---
.../random_shuffle.pass.cpp | 4 ++-
.../ranges.transform.binary.iterator.pass.cpp | 12 ++++++---
.../ranges.transform.binary.range.pass.cpp | 12 ++++++---
.../ranges.transform.unary.pass.cpp | 6 +++--
.../alg.ends_with/ranges.ends_with.pass.cpp | 6 +++--
.../alg.equal/ranges.equal.pass.cpp | 25 +++++++++++++------
.../alg.find.end/ranges.find_end.pass.cpp | 12 ++++++---
.../alg.foreach/ranges.for_each.pass.cpp | 7 ++++--
.../alg.foreach/ranges.for_each_n.pass.cpp | 4 ++-
.../alg.search/ranges.search.pass.cpp | 12 ++++++---
.../alg.search/ranges.search_n.pass.cpp | 6 +++--
.../ranges.starts_with.pass.cpp | 12 ++++++---
.../ranges.is_partitioned.pass.cpp | 7 ++++--
.../is.sorted/ranges.is_sorted.pass.cpp | 6 +++--
.../is.sorted/ranges.is_sorted_until.pass.cpp | 6 +++--
libcxx/utils/libcxx/test/params.py | 1 +
16 files changed, 94 insertions(+), 44 deletions(-)
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
index 087a498642881df..43932cc2696a467 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
@@ -17,6 +17,7 @@
// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
#include <algorithm>
+#include <array>
#include <cassert>
#include "test_macros.h"
@@ -26,7 +27,8 @@ template <class Iter>
void
test_with_iterator()
{
- int empty[] = {};
+ std::array<int, 0> empty_arr = {};
+ int* const empty = empty_arr.data();
std::random_shuffle(Iter(empty), Iter(empty));
const int all_elements[] = {1, 2, 3, 4};
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.binary.iterator.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.binary.iterator.pass.cpp
index b604263e525d272..74e41293b9f155f 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.binary.iterator.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.binary.iterator.pass.cpp
@@ -89,7 +89,8 @@ constexpr bool test_iterators() {
}
{ // first range empty
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int b[] = {5, 4, 3, 2, 1};
int c[5];
@@ -103,7 +104,8 @@ constexpr bool test_iterators() {
{ // second range empty
int a[] = {5, 4, 3, 2, 1};
- int b[] = {};
+ std::array<int, 0> b_arr = {};
+ int* const b = b_arr.data();
int c[5];
auto ret = std::ranges::transform(
@@ -115,8 +117,10 @@ constexpr bool test_iterators() {
}
{ // both ranges empty
- int a[] = {};
- int b[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
+ std::array<int, 0> b_arr = {};
+ int* const b = b_arr.data();
int c[5];
auto ret = std::ranges::transform(
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.binary.range.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.binary.range.pass.cpp
index 08ca8aa3fd9ee24..feaeafa397c7b96 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.binary.range.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.binary.range.pass.cpp
@@ -92,7 +92,8 @@ constexpr bool test_iterators() {
}
{ // first range empty
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int b[] = {5, 4, 3, 2, 1};
int c[5];
@@ -108,7 +109,8 @@ constexpr bool test_iterators() {
{ // second range empty
int a[] = {5, 4, 3, 2, 1};
- int b[] = {};
+ std::array<int, 0> b_arr = {};
+ int* const b = b_arr.data();
int c[5];
auto range1 = std::ranges::subrange(In1(a), Sent1(In1(a + 5)));
@@ -122,8 +124,10 @@ constexpr bool test_iterators() {
}
{ // both ranges empty
- int a[] = {};
- int b[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
+ std::array<int, 0> b_arr = {};
+ int* const b = b_arr.data();
int c[5];
auto range1 = std::ranges::subrange(In1(a), Sent1(In1(a)));
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.unary.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.unary.pass.cpp
index eeacf83664cfeef..c2d59b4e402d6c4 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.unary.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.transform/ranges.transform.unary.pass.cpp
@@ -108,7 +108,8 @@ constexpr bool test_iterators() {
{ // first range empty
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int b[5];
auto ret = std::ranges::transform(In1(a), Sent1(In1(a)), Out(b), [](int i) { return i * 2; });
assert(base(ret.in) == a);
@@ -116,7 +117,8 @@ constexpr bool test_iterators() {
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int b[5];
auto range = std::ranges::subrange(In1(a), Sent1(In1(a)));
auto ret = std::ranges::transform(range, Out(b), [](int i) { return i * 2; });
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.ends_with/ranges.ends_with.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.ends_with/ranges.ends_with.pass.cpp
index ce4dffffc4763a5..5fcb6c23dcd4a49 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.ends_with/ranges.ends_with.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.ends_with/ranges.ends_with.pass.cpp
@@ -156,7 +156,8 @@ constexpr void test_iterators() {
{ // suffix has zero length
int a[] = {1, 2, 3, 4, 5, 6};
- int p[] = {};
+ std::array<int, 0> p_arr = {};
+ int* const p = p_arr.data();
auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
auto suffix = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
{
@@ -170,7 +171,8 @@ constexpr void test_iterators() {
}
{ // range has zero length
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int p[] = {1, 2, 3, 4, 5, 6, 7, 8};
auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto suffix = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 8)));
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/ranges.equal.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/ranges.equal.pass.cpp
index 828f75ea11d358d..5e57cfa6094338d 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/ranges.equal.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/ranges.equal.pass.cpp
@@ -23,6 +23,7 @@
// Proj1 proj1 = {}, Proj2 proj2 = {});
#include <algorithm>
+#include <array>
#include <cassert>
#include <concepts>
#include <functional>
@@ -200,14 +201,18 @@ constexpr void test_iterators() {
{ // check that two empty ranges work
{
- int a[] = {};
- int b[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
+ std::array<int, 0> b_arr = {};
+ int* const b = b_arr.data();
auto ret = std::ranges::equal(Iter1(a), Sent1(Iter1(a)), Iter2(b), Sent2(Iter2(b)));
assert(ret);
}
{
- int a[] = {};
- int b[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
+ std::array<int, 0> b_arr = {};
+ int* const b = b_arr.data();
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto range2 = std::ranges::subrange(Iter2(b), Sent2(Iter2(b)));
auto ret = std::ranges::equal(range1, range2);
@@ -217,13 +222,15 @@ constexpr void test_iterators() {
{ // check that it works with the first range empty
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int b[] = {1, 2};
auto ret = std::ranges::equal(Iter1(a), Sent1(Iter1(a)), Iter2(b), Sent2(Iter2(b + 2)));
assert(!ret);
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int b[] = {1, 2};
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto range2 = std::ranges::subrange(Iter2(b), Sent2(Iter2(b + 2)));
@@ -235,13 +242,15 @@ constexpr void test_iterators() {
{ // check that it works with the second range empty
{
int a[] = {1, 2};
- int b[] = {};
+ std::array<int, 0> b_arr = {};
+ int* const b = b_arr.data();
auto ret = std::ranges::equal(Iter1(a), Sent1(Iter1(a + 2)), Iter2(b), Sent2(Iter2(b)));
assert(!ret);
}
{
int a[] = {1, 2};
- int b[] = {};
+ std::array<int, 0> b_arr = {};
+ int* const b = b_arr.data();
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 2)));
auto range2 = std::ranges::subrange(Iter2(b), Sent2(Iter2(b)));
auto ret = std::ranges::equal(range1, range2);
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/ranges.find_end.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/ranges.find_end.pass.cpp
index d826ff6ddf426b7..6753ea913a844c3 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/ranges.find_end.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/ranges.find_end.pass.cpp
@@ -182,14 +182,16 @@ constexpr void test_iterators() {
{ // pattern has zero length
{
int a[] = {6, 7, 8};
- int p[] = {};
+ std::array<int, 0> p_arr = {};
+ int* const p = p_arr.data();
auto ret = std::ranges::find_end(Iter1(a), Sent1(Iter1(a + 3)), Iter2(p), Sent2(Iter2(p)));
assert(base(ret.begin()) == a + 3);
assert(base(ret.end()) == a + 3);
}
{
int a[] = {6, 7, 8};
- int p[] = {};
+ std::array<int, 0> p_arr = {};
+ int* const p = p_arr.data();
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
auto range2 = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
auto ret = std::ranges::find_end(range1, range2);
@@ -200,14 +202,16 @@ constexpr void test_iterators() {
{ // range has zero length
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int p[] = {6, 7, 8};
auto ret = std::ranges::find_end(Iter1(a), Sent1(Iter1(a)), Iter2(p), Sent2(Iter2(p + 3)));
assert(base(ret.begin()) == a);
assert(base(ret.end()) == a);
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int p[] = {6, 7, 8};
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto range2 = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
index 52b91268edda6da..d2b02873b9677ea 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
@@ -19,6 +19,7 @@
// ranges::for_each(R&& r, Fun f, Proj proj = {});
#include <algorithm>
+#include <array>
#include <ranges>
#include "almost_satisfies_types.h"
@@ -98,11 +99,13 @@ constexpr void test_iterator() {
{ // check that an empty range works
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
std::ranges::for_each(Iter(a), Sent(Iter(a)), [](auto&) { assert(false); });
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
std::ranges::for_each(range, [](auto&) { assert(false); });
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp
index 913819979ca1cda..2b54de303cd871a 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp
@@ -16,6 +16,7 @@
// ranges::for_each_n(I first, iter_difference_t<I> n, Fun f, Proj proj = {});
#include <algorithm>
+#include <array>
#include <ranges>
#include "almost_satisfies_types.h"
@@ -58,7 +59,8 @@ constexpr void test_iterator() {
}
{ // check that an empty range works
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
std::ranges::for_each_n(Iter(a), 0, [](auto&) { assert(false); });
}
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search.pass.cpp
index b35729962492b12..0152093d40ca781 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search.pass.cpp
@@ -183,14 +183,16 @@ constexpr void test_iterators() {
{ // pattern has zero length
{
int a[] = {6, 7, 8};
- int p[] = {};
+ std::array<int, 0> p_arr = {};
+ int* const p = p_arr.data();
auto ret = std::ranges::search(Iter1(a), Sent1(Iter1(a + 3)), Iter2(p), Sent2(Iter2(p)));
assert(base(ret.begin()) == a);
assert(base(ret.end()) == a);
}
{
int a[] = {6, 7, 8};
- int p[] = {};
+ std::array<int, 0> p_arr = {};
+ int* const p = p_arr.data();
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
auto range2 = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
auto ret = std::ranges::search(range1, range2);
@@ -201,14 +203,16 @@ constexpr void test_iterators() {
{ // range has zero length
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int p[] = {6, 7, 8};
auto ret = std::ranges::search(Iter1(a), Sent1(Iter1(a)), Iter2(p), Sent2(Iter2(p + 3)));
assert(base(ret.begin()) == a);
assert(base(ret.end()) == a);
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int p[] = {6, 7, 8};
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto range2 = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search_n.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search_n.pass.cpp
index feca3b276c9a5c5..dbab7088d28f4e3 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search_n.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search_n.pass.cpp
@@ -171,13 +171,15 @@ constexpr void test_iterators() {
{ // range has zero length
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto ret = std::ranges::search_n(Iter(a), Sent(Iter(a)), 1, 1);
assert(base(ret.begin()) == a);
assert(base(ret.end()) == a);
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
auto ret = std::ranges::search_n(range, 1, 1);
assert(base(ret.begin()) == a);
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp
index 85c6bf96b2aa5df..86f476d75b2e6df 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.starts_with/ranges.starts_with.pass.cpp
@@ -136,14 +136,16 @@ constexpr void test_iterators() {
{ // prefix has zero length
{
int a[] = {1, 2, 3, 4, 5, 6};
- int p[] = {};
+ std::array<int, 0> p_arr = {};
+ int* const p = p_arr.data();
std::same_as<bool> decltype(auto) ret =
std::ranges::starts_with(Iter1(a), Sent1(Iter1(a + 6)), Iter2(p), Sent2(Iter2(p)));
assert(ret);
}
{
int a[] = {1, 2, 3, 4, 5, 6};
- int p[] = {};
+ std::array<int, 0> p_arr = {};
+ int* const p = p_arr.data();
auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 6)));
auto prefix = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
std::same_as<bool> decltype(auto) ret = std::ranges::starts_with(whole, prefix);
@@ -153,14 +155,16 @@ constexpr void test_iterators() {
{ // range has zero length
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int p[] = {1, 2, 3, 4, 5, 6, 7, 8};
std::same_as<bool> decltype(auto) ret =
std::ranges::starts_with(Iter1(a), Sent1(Iter1(a)), Iter2(p), Sent2(Iter2(p + 8)));
assert(!ret);
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
int p[] = {1, 2, 3, 4, 5, 6, 7, 8};
auto whole = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto prefix = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 8)));
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp
index 72b58f5534140bf..990ab0959a625f9 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp
@@ -19,6 +19,7 @@
#include <algorithm>
+#include <array>
#include <cassert>
#include "almost_satisfies_types.h"
@@ -131,12 +132,14 @@ constexpr void test_iterators() {
{ // check that an empty range is partitioned
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto ret = std::ranges::is_partitioned(Iter(a), Sent(Iter(a)), [](int i) { return i < 3; });
assert(ret);
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
auto ret = std::ranges::is_partitioned(range, [](int i) { return i < 3; });
assert(ret);
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted.pass.cpp
index b8831f76c58e535..5bc399d818b6a96 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted.pass.cpp
@@ -109,12 +109,14 @@ constexpr void test_iterators() {
{ // check that an empty range works
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto ret = std::ranges::is_sorted(Iter(a), Sent(Iter(a)));
assert(ret);
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
auto ret = std::ranges::is_sorted(range);
assert(ret);
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted_until.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted_until.pass.cpp
index c5a0fe8831237a5..9348e63fb93a26b 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted_until.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted_until.pass.cpp
@@ -110,12 +110,14 @@ constexpr void test_iterators() {
{ // check that an empty range works
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto ret = std::ranges::is_sorted_until(Iter(a), Sent(Iter(a)));
assert(base(ret) == a);
}
{
- int a[] = {};
+ std::array<int, 0> a_arr = {};
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
auto ret = std::ranges::is_sorted_until(range);
assert(base(ret) == a);
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 3fedbf972c0c822..ef532adc2cc02d8 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -48,6 +48,7 @@
# These warnings should be enabled in order to support the MSVC
# team using the test suite; They enable the warnings below and
# expect the test suite to be clean.
+ "-Wzero-length-array",
"-Wsign-compare",
"-Wunused-variable",
"-Wunused-parameter",
>From ca6b5a3d9cff65e2c773e8b5db59b3b6eb380d3e Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Fri, 1 Dec 2023 23:26:57 -0800
Subject: [PATCH 2/2] Apply clang-format from CI.
---
.../random_shuffle.pass.cpp | 20 +++++++++----------
.../alg.equal/ranges.equal.pass.cpp | 16 +++++++--------
.../alg.find.end/ranges.find_end.pass.cpp | 8 ++++----
.../alg.foreach/ranges.for_each.pass.cpp | 4 ++--
.../alg.foreach/ranges.for_each_n.pass.cpp | 2 +-
.../alg.search/ranges.search.pass.cpp | 8 ++++----
.../alg.search/ranges.search_n.pass.cpp | 4 ++--
.../ranges.is_partitioned.pass.cpp | 4 ++--
.../is.sorted/ranges.is_sorted.pass.cpp | 4 ++--
.../is.sorted/ranges.is_sorted_until.pass.cpp | 4 ++--
10 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
index 43932cc2696a467..462816b564bb083 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
@@ -27,19 +27,19 @@ template <class Iter>
void
test_with_iterator()
{
- std::array<int, 0> empty_arr = {};
- int* const empty = empty_arr.data();
- std::random_shuffle(Iter(empty), Iter(empty));
+ std::array<int, 0> empty_arr = {};
+ int* const empty = empty_arr.data();
+ std::random_shuffle(Iter(empty), Iter(empty));
- const int all_elements[] = {1, 2, 3, 4};
- int shuffled[] = {1, 2, 3, 4};
- const unsigned size = sizeof(all_elements)/sizeof(all_elements[0]);
+ const int all_elements[] = {1, 2, 3, 4};
+ int shuffled[] = {1, 2, 3, 4};
+ const unsigned size = sizeof(all_elements) / sizeof(all_elements[0]);
- std::random_shuffle(Iter(shuffled), Iter(shuffled+size));
- assert(std::is_permutation(shuffled, shuffled+size, all_elements));
+ std::random_shuffle(Iter(shuffled), Iter(shuffled + size));
+ assert(std::is_permutation(shuffled, shuffled + size, all_elements));
- std::random_shuffle(Iter(shuffled), Iter(shuffled+size));
- assert(std::is_permutation(shuffled, shuffled+size, all_elements));
+ std::random_shuffle(Iter(shuffled), Iter(shuffled + size));
+ assert(std::is_permutation(shuffled, shuffled + size, all_elements));
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/ranges.equal.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/ranges.equal.pass.cpp
index 5e57cfa6094338d..2266489987f3a1e 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/ranges.equal.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/ranges.equal.pass.cpp
@@ -202,17 +202,17 @@ constexpr void test_iterators() {
{ // check that two empty ranges work
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
std::array<int, 0> b_arr = {};
- int* const b = b_arr.data();
+ int* const b = b_arr.data();
auto ret = std::ranges::equal(Iter1(a), Sent1(Iter1(a)), Iter2(b), Sent2(Iter2(b)));
assert(ret);
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
std::array<int, 0> b_arr = {};
- int* const b = b_arr.data();
+ int* const b = b_arr.data();
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto range2 = std::ranges::subrange(Iter2(b), Sent2(Iter2(b)));
auto ret = std::ranges::equal(range1, range2);
@@ -223,14 +223,14 @@ constexpr void test_iterators() {
{ // check that it works with the first range empty
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
int b[] = {1, 2};
auto ret = std::ranges::equal(Iter1(a), Sent1(Iter1(a)), Iter2(b), Sent2(Iter2(b + 2)));
assert(!ret);
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
int b[] = {1, 2};
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto range2 = std::ranges::subrange(Iter2(b), Sent2(Iter2(b + 2)));
@@ -243,14 +243,14 @@ constexpr void test_iterators() {
{
int a[] = {1, 2};
std::array<int, 0> b_arr = {};
- int* const b = b_arr.data();
+ int* const b = b_arr.data();
auto ret = std::ranges::equal(Iter1(a), Sent1(Iter1(a + 2)), Iter2(b), Sent2(Iter2(b)));
assert(!ret);
}
{
int a[] = {1, 2};
std::array<int, 0> b_arr = {};
- int* const b = b_arr.data();
+ int* const b = b_arr.data();
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 2)));
auto range2 = std::ranges::subrange(Iter2(b), Sent2(Iter2(b)));
auto ret = std::ranges::equal(range1, range2);
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/ranges.find_end.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/ranges.find_end.pass.cpp
index 6753ea913a844c3..ed55b3c1bb42f7d 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/ranges.find_end.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/ranges.find_end.pass.cpp
@@ -183,7 +183,7 @@ constexpr void test_iterators() {
{
int a[] = {6, 7, 8};
std::array<int, 0> p_arr = {};
- int* const p = p_arr.data();
+ int* const p = p_arr.data();
auto ret = std::ranges::find_end(Iter1(a), Sent1(Iter1(a + 3)), Iter2(p), Sent2(Iter2(p)));
assert(base(ret.begin()) == a + 3);
assert(base(ret.end()) == a + 3);
@@ -191,7 +191,7 @@ constexpr void test_iterators() {
{
int a[] = {6, 7, 8};
std::array<int, 0> p_arr = {};
- int* const p = p_arr.data();
+ int* const p = p_arr.data();
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
auto range2 = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
auto ret = std::ranges::find_end(range1, range2);
@@ -203,7 +203,7 @@ constexpr void test_iterators() {
{ // range has zero length
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
int p[] = {6, 7, 8};
auto ret = std::ranges::find_end(Iter1(a), Sent1(Iter1(a)), Iter2(p), Sent2(Iter2(p + 3)));
assert(base(ret.begin()) == a);
@@ -211,7 +211,7 @@ constexpr void test_iterators() {
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
int p[] = {6, 7, 8};
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto range2 = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
index d2b02873b9677ea..2e631a72725ff49 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp
@@ -100,12 +100,12 @@ constexpr void test_iterator() {
{ // check that an empty range works
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
std::ranges::for_each(Iter(a), Sent(Iter(a)), [](auto&) { assert(false); });
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
std::ranges::for_each(range, [](auto&) { assert(false); });
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp
index 2b54de303cd871a..4d4b743ffd1f493 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp
@@ -60,7 +60,7 @@ constexpr void test_iterator() {
{ // check that an empty range works
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
std::ranges::for_each_n(Iter(a), 0, [](auto&) { assert(false); });
}
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search.pass.cpp
index 0152093d40ca781..97332408f626a40 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search.pass.cpp
@@ -184,7 +184,7 @@ constexpr void test_iterators() {
{
int a[] = {6, 7, 8};
std::array<int, 0> p_arr = {};
- int* const p = p_arr.data();
+ int* const p = p_arr.data();
auto ret = std::ranges::search(Iter1(a), Sent1(Iter1(a + 3)), Iter2(p), Sent2(Iter2(p)));
assert(base(ret.begin()) == a);
assert(base(ret.end()) == a);
@@ -192,7 +192,7 @@ constexpr void test_iterators() {
{
int a[] = {6, 7, 8};
std::array<int, 0> p_arr = {};
- int* const p = p_arr.data();
+ int* const p = p_arr.data();
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a + 3)));
auto range2 = std::ranges::subrange(Iter2(p), Sent2(Iter2(p)));
auto ret = std::ranges::search(range1, range2);
@@ -204,7 +204,7 @@ constexpr void test_iterators() {
{ // range has zero length
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
int p[] = {6, 7, 8};
auto ret = std::ranges::search(Iter1(a), Sent1(Iter1(a)), Iter2(p), Sent2(Iter2(p + 3)));
assert(base(ret.begin()) == a);
@@ -212,7 +212,7 @@ constexpr void test_iterators() {
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
int p[] = {6, 7, 8};
auto range1 = std::ranges::subrange(Iter1(a), Sent1(Iter1(a)));
auto range2 = std::ranges::subrange(Iter2(p), Sent2(Iter2(p + 3)));
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search_n.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search_n.pass.cpp
index dbab7088d28f4e3..4122db99ff8cb6a 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search_n.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.search/ranges.search_n.pass.cpp
@@ -172,14 +172,14 @@ constexpr void test_iterators() {
{ // range has zero length
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto ret = std::ranges::search_n(Iter(a), Sent(Iter(a)), 1, 1);
assert(base(ret.begin()) == a);
assert(base(ret.end()) == a);
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
auto ret = std::ranges::search_n(range, 1, 1);
assert(base(ret.begin()) == a);
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp
index 990ab0959a625f9..64fb1f8cf89f3e6 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.partitions/ranges.is_partitioned.pass.cpp
@@ -133,13 +133,13 @@ constexpr void test_iterators() {
{ // check that an empty range is partitioned
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto ret = std::ranges::is_partitioned(Iter(a), Sent(Iter(a)), [](int i) { return i < 3; });
assert(ret);
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
auto ret = std::ranges::is_partitioned(range, [](int i) { return i < 3; });
assert(ret);
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted.pass.cpp
index 5bc399d818b6a96..57a968d770ac672 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted.pass.cpp
@@ -110,13 +110,13 @@ constexpr void test_iterators() {
{ // check that an empty range works
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto ret = std::ranges::is_sorted(Iter(a), Sent(Iter(a)));
assert(ret);
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
auto ret = std::ranges::is_sorted(range);
assert(ret);
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted_until.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted_until.pass.cpp
index 9348e63fb93a26b..ec2cb4cf46f10fc 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted_until.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.sort/is.sorted/ranges.is_sorted_until.pass.cpp
@@ -111,13 +111,13 @@ constexpr void test_iterators() {
{ // check that an empty range works
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto ret = std::ranges::is_sorted_until(Iter(a), Sent(Iter(a)));
assert(base(ret) == a);
}
{
std::array<int, 0> a_arr = {};
- int* const a = a_arr.data();
+ int* const a = a_arr.data();
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a)));
auto ret = std::ranges::is_sorted_until(range);
assert(base(ret) == a);
More information about the libcxx-commits
mailing list