Skip to content

Commit ef83894

Browse files
[libc++][test] Fix zero-length arrays and copy-pasted lambdas in ranges.contains.pass.cpp (#79792)
* Fix MSVC error C2466: cannot allocate an array of constant size 0 + MSVC rejects this non-Standard extension. Previous fixes: #74183 * Fix MSVC warning C4805: `'=='`: unsafe mix of type `'int'` and type `'const bool'` in operation + AFAICT, these lambdas were copy-pasted, and didn't intend to take and return `int` here. This part of the test is using `vector<bool>` for random-access but non-contiguous iterators, and it's checking how many times the projection is invoked, but the projection doesn't need to do anything squirrely, it should otherwise be an identity. * Fix typos: "continuous" => "contiguous".
1 parent c9535d7 commit ef83894

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23
2020

2121
#include <algorithm>
22+
#include <array>
2223
#include <cassert>
2324
#include <list>
2425
#include <ranges>
@@ -89,8 +90,8 @@ constexpr void test_iterators() {
8990
}
9091

9192
{ // check that an empty range works
92-
ValueT a[] = {};
93-
auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a)));
93+
std::array<ValueT, 0> a = {};
94+
auto whole = std::ranges::subrange(Iter(a.data()), Sent(Iter(a.data())));
9495
{
9596
bool ret = std::ranges::contains(whole.begin(), whole.end(), 1);
9697
assert(!ret);
@@ -164,7 +165,7 @@ constexpr bool test() {
164165
});
165166
});
166167

167-
{ // count invocations of the projection for continuous iterators
168+
{ // count invocations of the projection for contiguous iterators
168169
int a[] = {1, 9, 0, 13, 25};
169170
int projection_count = 0;
170171
{
@@ -215,22 +216,22 @@ constexpr bool test() {
215216
}
216217
}
217218

218-
{ // check invocations of the projection for non-continuous iterators
219+
{ // check invocations of the projection for non-contiguous iterators
219220
std::vector<bool> whole{false, false, true, false};
220221
int projection_count = 0;
221222
{
222-
bool ret = std::ranges::contains(whole.begin(), whole.end(), true, [&](int i) {
223+
bool ret = std::ranges::contains(whole.begin(), whole.end(), true, [&](bool b) {
223224
++projection_count;
224-
return i;
225+
return b;
225226
});
226227
assert(ret);
227228
assert(projection_count == 3);
228229
projection_count = 0;
229230
}
230231
{
231-
bool ret = std::ranges::contains(whole, true, [&](int i) {
232+
bool ret = std::ranges::contains(whole, true, [&](bool b) {
232233
++projection_count;
233-
return i;
234+
return b;
234235
});
235236
assert(ret);
236237
assert(projection_count == 3);

0 commit comments

Comments
 (0)