[llvm-branch-commits] [libcxx] 187bac7 - [libc++][ranges][NFC] Make sure all implemented algorithms are enabled in "robust" tests.

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 8 15:38:33 PDT 2022


Author: Konstantin Varlamov
Date: 2022-08-08T13:29:17-07:00
New Revision: 187bac761200d6b1d36346c5e0d6b3bb035377e6

URL: https://github.com/llvm/llvm-project/commit/187bac761200d6b1d36346c5e0d6b3bb035377e6
DIFF: https://github.com/llvm/llvm-project/commit/187bac761200d6b1d36346c5e0d6b3bb035377e6.diff

LOG: [libc++][ranges][NFC] Make sure all implemented algorithms are enabled in "robust" tests.

Also fix `std::find_first_of` (which accidentally copied the predicate
in the implementation).

Differential Revision: https://reviews.llvm.org/D131235

(cherry picked from commit 8ac015caf627a0db89540950d6343e955ba9500b)

Added: 
    

Modified: 
    libcxx/include/__algorithm/find_first_of.h
    libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
    libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp
    libcxx/test/std/algorithms/ranges_result_alias_declarations.compile.pass.cpp
    libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp
    libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp
    libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__algorithm/find_first_of.h b/libcxx/include/__algorithm/find_first_of.h
index b968329fc3186..2096b0f0c9a53 100644
--- a/libcxx/include/__algorithm/find_first_of.h
+++ b/libcxx/include/__algorithm/find_first_of.h
@@ -24,7 +24,8 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
 _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1,
                                                                    _ForwardIterator1 __last1,
                                                                    _ForwardIterator2 __first2,
-                                                                   _ForwardIterator2 __last2, _BinaryPredicate __pred) {
+                                                                   _ForwardIterator2 __last2,
+                                                                   _BinaryPredicate&& __pred) {
   for (; __first1 != __last1; ++__first1)
     for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
       if (__pred(*__first1, *__j))

diff  --git a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
index 419e2eb412cc2..343ef41c4b92d 100644
--- a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp
@@ -121,9 +121,9 @@ constexpr bool all_the_algorithms()
     (void)std::ranges::for_each(first, last, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
     (void)std::ranges::for_each(a, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
     (void)std::ranges::for_each_n(first, count, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
-    //(void)std::ranges::generate(first, last, NullaryValue(&copies)); assert(copies == 0);
-    //(void)std::ranges::generate(a, NullaryValue(&copies)); assert(copies == 0);
-    //(void)std::ranges::generate_n(first, count, NullaryValue(&copies)); assert(copies == 0);
+    (void)std::ranges::generate(first, last, NullaryValue(&copies)); assert(copies == 0);
+    (void)std::ranges::generate(a, NullaryValue(&copies)); assert(copies == 0);
+    (void)std::ranges::generate_n(first, count, NullaryValue(&copies)); assert(copies == 0);
     (void)std::ranges::includes(first, last, first2, last2, Less(&copies)); assert(copies == 0);
     (void)std::ranges::includes(a, b, Less(&copies)); assert(copies == 0);
     (void)std::ranges::is_heap(first, last, Less(&copies)); assert(copies == 0);

diff  --git a/libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp b/libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp
index 66b8b3637f5f3..0f50d1cdaa827 100644
--- a/libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp
@@ -120,7 +120,7 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
 #endif
     (void)std::equal_range(first, last, value, Less<T>(&copies)); assert(copies == 0);
     (void)std::find_end(first, last, first2, mid2, Equal<T>(&copies)); assert(copies == 0);
-    //(void)std::find_first_of(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
+    (void)std::find_first_of(first, last, first2, last2, Equal<T>(&copies)); assert(copies == 0);
     (void)std::find_if(first, last, UnaryTrue<T>(&copies)); assert(copies == 0);
     (void)std::find_if_not(first, last, UnaryTrue<T>(&copies)); assert(copies == 0);
     (void)std::for_each(first, last, UnaryVoid<T>(&copies)); assert(copies == 1); copies = 0;

diff  --git a/libcxx/test/std/algorithms/ranges_result_alias_declarations.compile.pass.cpp b/libcxx/test/std/algorithms/ranges_result_alias_declarations.compile.pass.cpp
index 953fc72f18dec..d50de6ec0967d 100644
--- a/libcxx/test/std/algorithms/ranges_result_alias_declarations.compile.pass.cpp
+++ b/libcxx/test/std/algorithms/ranges_result_alias_declarations.compile.pass.cpp
@@ -36,8 +36,8 @@ static_assert(std::is_same_v<in_out_result<int, long>, remove_copy_result<int, l
 static_assert(std::is_same_v<in_out_result<int, long>, remove_copy_if_result<int, long>>);
 static_assert(std::is_same_v<in_out_result<int, long>, replace_copy_result<int, long>>);
 static_assert(std::is_same_v<in_out_result<int, long>, replace_copy_if_result<int, long>>);
-// static_assert(std::is_same_v<in_out_result<int, long>, reverse_copy_result<int, long>>);
-// static_assert(std::is_same_v<in_out_result<int, long>, rotate_copy_result<int, long>>);
+static_assert(std::is_same_v<in_out_result<int, long>, reverse_copy_result<int, long>>);
+static_assert(std::is_same_v<in_out_result<int, long>, rotate_copy_result<int, long>>);
 static_assert(std::is_same_v<in_out_result<int, long>, set_
diff erence_result<int, long>>);
 static_assert(std::is_same_v<in_out_result<int, long>, unary_transform_result<int, long>>);
 static_assert(std::is_same_v<in_out_result<int, long>, uninitialized_copy_result<int, long>>);

diff  --git a/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp
index e42892d37abaa..7da2ee5cbba6e 100644
--- a/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp
+++ b/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp
@@ -76,8 +76,10 @@ constexpr bool test_all() {
   using std::ranges::mismatch_result;
   using std::ranges::move_result;
   using std::ranges::move_backward_result;
+  using std::ranges::next_permutation_result;
   using std::ranges::partial_sort_copy_result;
   using std::ranges::partition_copy_result;
+  using std::ranges::prev_permutation_result;
   using std::ranges::remove_copy_result;
   using std::ranges::remove_copy_if_result;
   using std::ranges::replace_copy_result;
@@ -199,8 +201,8 @@ constexpr bool test_all() {
   dangling_1st(std::ranges::push_heap, in);
   dangling_1st(std::ranges::pop_heap, in);
   dangling_1st(std::ranges::sort_heap, in);
-  //dangling_1st(std::ranges::prev_permutation, in);
-  //dangling_1st(std::ranges::next_permutation, in);
+  dangling_1st<prev_permutation_result<dangling>>(std::ranges::prev_permutation, in);
+  dangling_1st<next_permutation_result<dangling>>(std::ranges::next_permutation, in);
 
   return true;
 }

diff  --git a/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp
index 5517e7b221bc6..05599e2583687 100644
--- a/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp
+++ b/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp
@@ -69,7 +69,6 @@ constexpr void run_tests() {
   int count = 1;
 
   auto unary_pred = [](const Proxy<T&>&) { return true; };
-  //auto binary_pred = [](const Proxy<T>&, const Proxy<T>&) { return return false; };
   auto binary_func = [](const Proxy<T>&, const Proxy<T>&) -> Proxy<T> { return Proxy<T>(T()); };
   auto gen = [] { return Proxy<T>(T{42}); };
 
@@ -87,7 +86,7 @@ constexpr void run_tests() {
   test(std::ranges::partition_point, in, unary_pred);
   test(std::ranges::lower_bound, in, x);
   test(std::ranges::upper_bound, in, x);
-  //test(std::ranges::equal_range, in, x);
+  test(std::ranges::equal_range, in, x);
   test(std::ranges::binary_search, in, x);
 
   test(std::ranges::min_element, in);
@@ -169,8 +168,8 @@ constexpr void run_tests() {
   test(std::ranges::push_heap, in);
   test(std::ranges::pop_heap, in);
   test(std::ranges::sort_heap, in);
-  //test(std::ranges::prev_permutation, in);
-  //test(std::ranges::next_permutation, in);
+  test(std::ranges::prev_permutation, in);
+  test(std::ranges::next_permutation, in);
 
   // The algorithms that work on uninitialized memory have constraints that prevent proxy iterators from being used with
   // them.

diff  --git a/libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp b/libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp
index 9e5398bf16126..eba435123b2a3 100644
--- a/libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp
+++ b/libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp
@@ -56,7 +56,6 @@ int a[10];
 auto odd = [](int x) { return x % 2 != 0; };
 auto triple = [](int x) { return 3*x; };
 auto gen = [] { return 42; };
-//auto plus = [](int x, int y) { return x == y; };
 std::mt19937 g;
 
 // [algorithm.syn]
@@ -79,7 +78,7 @@ static_assert(test(std::ranges::fill, a, 42));
 static_assert(test(std::ranges::fill_n, a, 10, 42));
 static_assert(test(std::ranges::find, a, 42));
 static_assert(test(std::ranges::find_end, a, a));
-//static_assert(test(std::ranges::find_first_of, a, a));
+static_assert(test(std::ranges::find_first_of, a, a));
 static_assert(test(std::ranges::find_if, a, odd));
 static_assert(test(std::ranges::find_if_not, a, odd));
 static_assert(test(std::ranges::for_each, a, odd));
@@ -107,7 +106,7 @@ static_assert(test(std::ranges::minmax_element, a));
 static_assert(test(std::ranges::mismatch, a, a));
 static_assert(test(std::ranges::move, a, a));
 static_assert(test(std::ranges::move_backward, a, a));
-//static_assert(test(std::ranges::next_permutation, a));
+static_assert(test(std::ranges::next_permutation, a));
 static_assert(test(std::ranges::none_of, a, odd));
 static_assert(test(std::ranges::nth_element, a, a+5));
 static_assert(test(std::ranges::partial_sort, a, a+5));
@@ -116,7 +115,7 @@ static_assert(test(std::ranges::partition, a, odd));
 static_assert(test(std::ranges::partition_copy, a, a, a, odd));
 static_assert(test(std::ranges::partition_point, a, odd));
 static_assert(test(std::ranges::pop_heap, a));
-//static_assert(test(std::ranges::prev_permutation, a));
+static_assert(test(std::ranges::prev_permutation, a));
 static_assert(test(std::ranges::push_heap, a));
 static_assert(test(std::ranges::remove, a, 42));
 static_assert(test(std::ranges::remove_copy, a, a, 42));


        


More information about the llvm-branch-commits mailing list