[libcxx-commits] [libcxx] 75eb3bd - [libc++] Remove tests from ranges.pass.cpp which violate semantic requirements
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue May 23 08:59:42 PDT 2023
Author: Nikolas Klauser
Date: 2023-05-23T08:59:37-07:00
New Revision: 75eb3bd1a43db7d72be0a12edce4b1f6a2bb1fa7
URL: https://github.com/llvm/llvm-project/commit/75eb3bd1a43db7d72be0a12edce4b1f6a2bb1fa7
DIFF: https://github.com/llvm/llvm-project/commit/75eb3bd1a43db7d72be0a12edce4b1f6a2bb1fa7.diff
LOG: [libc++] Remove tests from ranges.pass.cpp which violate semantic requirements
This also removes some tests which we have grouped together into robust_from_*.pass.cpp tests.
Specifically, checking that
- `ranges::dangling` is returned is done in `libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp`
- `std::invoke` is used is done in `libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp`.
- implicit conversion to bool works is done in `libcxx/test/std/algorithms/ranges_robust_against_nonbool_predicates.pass.cpp`
Checking the comparison order is invalid because the `operator==` isn't symmetric.
Checking what the exact type of `operator==` is, is invalid because comparing the same object has to yield the same results if the objects are not modified.
Reviewed By: ldionne, #libc
Spies: EricWF, libcxx-commits
Differential Revision: https://reviews.llvm.org/D150588
Added:
Modified:
libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
index e950797ffdbe8..4edded01e2303 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/ranges.find.pass.cpp
@@ -70,25 +70,6 @@ constexpr void test_iterators() {
}
}
-struct OneWayComparable {
- bool isLeft;
- friend constexpr bool operator==(OneWayComparable l, OneWayComparable) { return l.isLeft; }
-};
-
-struct NonConstComparableLValue {
- friend constexpr bool operator==(const NonConstComparableLValue&, const NonConstComparableLValue&) { return false; }
- friend constexpr bool operator==(NonConstComparableLValue&, NonConstComparableLValue&) { return false; }
- friend constexpr bool operator==(const NonConstComparableLValue&, NonConstComparableLValue&) { return false; }
- friend constexpr bool operator==(NonConstComparableLValue&, const NonConstComparableLValue&) { return true; }
-};
-
-struct NonConstComparableRValue {
- friend constexpr bool operator==(const NonConstComparableRValue&, const NonConstComparableRValue&) { return false; }
- friend constexpr bool operator==(const NonConstComparableRValue&&, const NonConstComparableRValue&&) { return false; }
- friend constexpr bool operator==(NonConstComparableRValue&&, NonConstComparableRValue&&) { return false; }
- friend constexpr bool operator==(NonConstComparableRValue&&, const NonConstComparableRValue&) { return true; }
-};
-
constexpr bool test() {
test_iterators<int*>();
test_iterators<const int*>();
@@ -150,12 +131,6 @@ constexpr bool test() {
}
}
- {
- // check that ranges::dangling is returned
- [[maybe_unused]] std::same_as<std::ranges::dangling> auto ret =
- std::ranges::find(std::array{1, 2}, 3);
- }
-
{
// check that an iterator is returned with a borrowing range
int a[] = {1, 2, 3, 4};
@@ -164,14 +139,6 @@ constexpr bool test() {
assert(*ret == 1);
}
- {
- // check that std::invoke is used
- struct S { int i; };
- S a[] = { S{1}, S{3}, S{2} };
- std::same_as<S*> auto ret = std::ranges::find(a, 4, &S::i);
- assert(ret == a + 3);
- }
-
{
// count invocations of the projection
{
@@ -192,47 +159,6 @@ constexpr bool test() {
}
}
- {
- // check comparison order
- {
- OneWayComparable a[] = { OneWayComparable{true} };
- auto ret = std::ranges::find(a, a + 1, OneWayComparable{false});
- assert(ret == a);
- }
- {
- OneWayComparable a[] = { OneWayComparable{true} };
- auto ret = std::ranges::find(a, OneWayComparable{false});
- assert(ret == a);
- }
- }
-
- {
- // check that the return type of `iter::operator*` doesn't change
- {
- NonConstComparableLValue a[] = { NonConstComparableLValue{} };
- auto ret = std::ranges::find(a, a + 1, NonConstComparableLValue{});
- assert(ret == a);
- }
- {
- using It = std::move_iterator<NonConstComparableRValue*>;
- NonConstComparableRValue a[] = { NonConstComparableRValue{} };
- auto ret = std::ranges::find(It(a), It(a + 1), NonConstComparableRValue{});
- assert(ret.base() == a);
- }
- {
- NonConstComparableLValue a[] = { NonConstComparableLValue{} };
- auto ret = std::ranges::find(a, NonConstComparableLValue{});
- assert(ret == a);
- }
- {
- using It = std::move_iterator<NonConstComparableRValue*>;
- NonConstComparableRValue a[] = { NonConstComparableRValue{} };
- auto range = std::ranges::subrange(It(a), It(a + 1));
- auto ret = std::ranges::find(range, NonConstComparableRValue{});
- assert(ret.base() == a);
- }
- }
-
{
// check that an empty range works
{
@@ -247,20 +173,6 @@ constexpr bool test() {
}
}
- {
- // check that the implicit conversion to bool works
- {
- StrictComparable<int> a[] = {1, 2, 3, 4};
- auto ret = std::ranges::find(a, a + 4, StrictComparable<int>{2});
- assert(ret == a + 1);
- }
- {
- StrictComparable<int> a[] = {1, 2, 3, 4};
- auto ret = std::ranges::find(a, StrictComparable<int>{2});
- assert(ret == a + 1);
- }
- }
-
return true;
}
More information about the libcxx-commits
mailing list