aboutsummaryrefslogtreecommitdiff
path: root/libcxx/test/std/algorithms/alg.nonmodifying
diff options
context:
space:
mode:
authornicole mazzuca <nicole@strega-nil.co>2024-07-30 11:28:56 +0200
committerGitHub <noreply@github.com>2024-07-30 02:28:56 -0700
commitc6b192ac2e1441b3484781488adef2986408ebdf (patch)
treecdffb04198a47fed7f8e51243c07289f277456f3 /libcxx/test/std/algorithms/alg.nonmodifying
parent55357d8b92e32999aca83daab017df35e87e9ed2 (diff)
downloadllvm-c6b192ac2e1441b3484781488adef2986408ebdf.zip
llvm-c6b192ac2e1441b3484781488adef2986408ebdf.tar.gz
llvm-c6b192ac2e1441b3484781488adef2986408ebdf.tar.bz2
[libc++][test] Do not assume array::iterator is a pointer (#100603)
In the tests I added for `ranges::find_last{_if{_not}}`, I accidentally introduced an assumption that `same_as<array<T, 0>::iterator, T*>`; this is a faulty assumption on MSVC-STL. Fixes #100498.
Diffstat (limited to 'libcxx/test/std/algorithms/alg.nonmodifying')
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp6
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp17
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp17
3 files changed, 30 insertions, 10 deletions
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp
index 2a2b12f..9da8c26 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last.pass.cpp
@@ -25,6 +25,7 @@
#include <algorithm>
#include <array>
#include <cassert>
+#include <memory>
#include <ranges>
#include <vector>
@@ -61,7 +62,8 @@ template <class It, class Sent = It>
constexpr void test_iterators() {
using ValueT = std::iter_value_t<It>;
auto make_range = [](auto& a) {
- return std::ranges::subrange(It(std::ranges::begin(a)), Sent(It(std::ranges::end(a))));
+ return std::ranges::subrange(
+ It(std::to_address(std::ranges::begin(a))), Sent(It(std::to_address(std::ranges::end(a)))));
};
{ // simple test
{
@@ -91,7 +93,7 @@ constexpr void test_iterators() {
std::array<ValueT, 0> a = {};
auto ret = std::ranges::find_last(make_range(a), 1).begin();
- assert(ret == It(a.begin()));
+ assert(ret == It(a.data()));
}
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp
index a15f81b..107fcf9 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if.pass.cpp
@@ -92,14 +92,14 @@ constexpr void test_iterator_classes() {
{
std::array<int, 0> a = {};
- auto ret = std::ranges::find_last_if(it(a.data()), sent(it(a.data())), [](auto&&) { return true; }).begin();
- assert(ret == it(a.data()));
+ auto ret = std::ranges::find_last_if(it(a.begin()), sent(it(a.end())), [](auto&&) { return true; }).begin();
+ assert(ret == it(a.end()));
}
{
std::array<int, 0> a = {};
auto ret = std::ranges::find_last_if(make_range<it, sent>(a), [](auto&&) { return true; }).begin();
- assert(ret == it(a.begin()));
+ assert(ret == it(a.end()));
}
}
@@ -183,8 +183,17 @@ struct NonConstComparable {
friend constexpr bool operator==(NonConstComparable&, const NonConstComparable&) { return true; }
};
+// TODO: this should really use `std::const_iterator`
template <class T>
-using add_const_to_ptr_t = std::add_pointer_t<std::add_const_t<std::remove_pointer_t<T>>>;
+struct add_const_to_ptr {
+ using type = T;
+};
+template <class T>
+struct add_const_to_ptr<T*> {
+ using type = const T*;
+};
+template <class T>
+using add_const_to_ptr_t = typename add_const_to_ptr<T>::type;
constexpr bool test() {
test_iterator_classes<std::type_identity_t, std::type_identity_t>();
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp
index bb0e411..6602ac5 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.last/ranges.find_last_if_not.pass.cpp
@@ -92,14 +92,14 @@ constexpr void test_iterator_classes() {
{
std::array<int, 0> a = {};
- auto ret = std::ranges::find_last_if_not(it(a.data()), sent(it(a.data())), [](auto&&) { return false; }).begin();
- assert(ret == it(a.data()));
+ auto ret = std::ranges::find_last_if_not(it(a.begin()), sent(it(a.end())), [](auto&&) { return false; }).begin();
+ assert(ret == it(a.end()));
}
{
std::array<int, 0> a = {};
auto ret = std::ranges::find_last_if_not(make_range<it, sent>(a), [](auto&&) { return false; }).begin();
- assert(ret == it(a.begin()));
+ assert(ret == it(a.end()));
}
}
@@ -183,8 +183,17 @@ struct NonConstComparable {
friend constexpr bool operator!=(NonConstComparable&, const NonConstComparable&) { return false; }
};
+// TODO: this should really use `std::const_iterator`
template <class T>
-using add_const_to_ptr_t = std::add_pointer_t<std::add_const_t<std::remove_pointer_t<T>>>;
+struct add_const_to_ptr {
+ using type = T;
+};
+template <class T>
+struct add_const_to_ptr<T*> {
+ using type = const T*;
+};
+template <class T>
+using add_const_to_ptr_t = typename add_const_to_ptr<T>::type;
constexpr bool test() {
test_iterator_classes<std::type_identity_t, std::type_identity_t>();