[libcxx-commits] [libcxx] [libc++][test][NFC] Introduce `TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED` (PR #132593)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Mar 23 08:12:08 PDT 2025


https://github.com/frederick-vs-ja updated https://github.com/llvm/llvm-project/pull/132593

>From 3930935d30d539658956e1927605949556b17427 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Thu, 20 Mar 2025 02:46:28 +0800
Subject: [PATCH 1/2] [libc++][test] Introduce
 `TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED`

And use it for test cases that became constant-evaluation-suitable due
to P2562R1.

`TEST_STD_AT_LEAST_(20|23)_OR_RUNTIME_EVALUATED` are the precedents.
---
 ...es_robust_against_copying_comparators.pass.cpp | 10 ++--------
 ...es_robust_against_copying_projections.pass.cpp | 10 ++--------
 .../ranges_robust_against_dangling.pass.cpp       | 15 +++------------
 ...ranges_robust_against_omitting_invoke.pass.cpp | 15 +++------------
 ...ranges_robust_against_proxy_iterators.pass.cpp | 15 +++------------
 .../algorithms/robust_against_adl_on_new.pass.cpp |  5 +----
 ...against_proxy_iterators_lifetime_bugs.pass.cpp | 10 ++--------
 .../robust_re_difference_type.compile.pass.cpp    | 10 ++--------
 libcxx/test/support/test_macros.h                 |  6 ++++++
 9 files changed, 24 insertions(+), 72 deletions(-)

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 ee3619e0e6bcc..dd026444330ea 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
@@ -150,10 +150,7 @@ constexpr bool all_the_algorithms()
     (void)std::ranges::is_sorted(a, Less(&copies)); assert(copies == 0);
     (void)std::ranges::is_sorted_until(first, last, Less(&copies)); assert(copies == 0);
     (void)std::ranges::is_sorted_until(a, Less(&copies)); assert(copies == 0);
-#if TEST_STD_VER < 26
-    if (!std::is_constant_evaluated())
-#endif
-    {
+    if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
       (void)std::ranges::inplace_merge(first, mid, last, Less(&copies));
       assert(copies == 0);
       (void)std::ranges::inplace_merge(a, mid, Less(&copies));
@@ -230,10 +227,7 @@ constexpr bool all_the_algorithms()
     (void)std::ranges::sort(a, Less(&copies)); assert(copies == 0);
     (void)std::ranges::sort_heap(first, last, Less(&copies)); assert(copies == 0);
     (void)std::ranges::sort_heap(a, Less(&copies)); assert(copies == 0);
-#if TEST_STD_VER < 26
-    if (!std::is_constant_evaluated())
-#endif
-    {
+    if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
       (void)std::ranges::stable_partition(first, last, UnaryTrue(&copies));
       assert(copies == 0);
       (void)std::ranges::stable_partition(a, UnaryTrue(&copies));
diff --git a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
index 1a85d1f33cf10..4919590ddffdc 100644
--- a/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
+++ b/libcxx/test/libcxx/algorithms/ranges_robust_against_copying_projections.pass.cpp
@@ -147,10 +147,7 @@ constexpr bool all_the_algorithms()
     (void)std::ranges::is_sorted(a, Less(), Proj(&copies)); assert(copies == 0);
     (void)std::ranges::is_sorted_until(first, last, Less(), Proj(&copies)); assert(copies == 0);
     (void)std::ranges::is_sorted_until(a, Less(), Proj(&copies)); assert(copies == 0);
-#if TEST_STD_VER < 26
-    if (!std::is_constant_evaluated())
-#endif
-    {
+    if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
       (void)std::ranges::inplace_merge(first, mid, last, Less(), Proj(&copies));
       assert(copies == 0);
       (void)std::ranges::inplace_merge(a, mid, Less(), Proj(&copies));
@@ -235,10 +232,7 @@ constexpr bool all_the_algorithms()
     (void)std::ranges::sort(a, Less(), Proj(&copies)); assert(copies == 0);
     (void)std::ranges::sort_heap(first, last, Less(), Proj(&copies)); assert(copies == 0);
     (void)std::ranges::sort_heap(a, Less(), Proj(&copies)); assert(copies == 0);
-#if TEST_STD_VER < 26
-    if (!std::is_constant_evaluated())
-#endif
-    {
+    if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
       (void)std::ranges::stable_partition(first, last, UnaryTrue(), Proj(&copies));
       assert(copies == 0);
       (void)std::ranges::stable_partition(a, UnaryTrue(), Proj(&copies));
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 12743a08e3192..2691269ef1b28 100644
--- a/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp
+++ b/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp
@@ -197,25 +197,16 @@ constexpr bool test_all() {
     dangling_1st(std::ranges::shuffle, in, rand_gen());
   dangling_1st(std::ranges::unique, in);
   dangling_1st(std::ranges::partition, in, unary_pred);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     dangling_1st(std::ranges::stable_partition, in, unary_pred);
   }
   dangling_1st(std::ranges::sort, in);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     dangling_1st(std::ranges::stable_sort, in);
   }
   dangling_1st(std::ranges::partial_sort, in, mid);
   dangling_1st(std::ranges::nth_element, in, mid);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     dangling_1st(std::ranges::inplace_merge, in, mid);
   }
   dangling_1st(std::ranges::make_heap, in);
diff --git a/libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp
index 914e31d133805..ca87f6e6984f4 100644
--- a/libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp
+++ b/libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp
@@ -164,25 +164,16 @@ constexpr bool test_all() {
   // For `shuffle`, whether the given generator is invoked via `std::invoke` is not observable.
   test(std::ranges::unique, in, &Foo::binary_pred, &Bar::val);
   test(std::ranges::partition, in, &Foo::unary_pred, &Bar::val);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     test(std::ranges::stable_partition, in, &Foo::unary_pred, &Bar::val);
   }
   test(std::ranges::sort, in, &Foo::binary_pred, &Bar::val);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     test(std::ranges::stable_sort, in, &Foo::binary_pred, &Bar::val);
   }
   test_mid(std::ranges::partial_sort, in, mid, &Foo::binary_pred, &Bar::val);
   test_mid(std::ranges::nth_element, in, mid, &Foo::binary_pred, &Bar::val);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     test_mid(std::ranges::inplace_merge, in, mid, &Foo::binary_pred, &Bar::val);
   }
   test(std::ranges::make_heap, in, &Foo::binary_pred, &Bar::val);
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 2ed2cb54788a6..bebaeb01f22e9 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
@@ -167,25 +167,16 @@ constexpr void run_tests() {
   }
   test(std::ranges::unique, in);
   test(std::ranges::partition, in, unary_pred);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     test(std::ranges::stable_partition, in, unary_pred);
   }
   test(std::ranges::sort, in);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     test(std::ranges::stable_sort, in);
   }
   test_mid(std::ranges::partial_sort, in, mid);
   test_mid(std::ranges::nth_element, in, mid);
-#if TEST_STD_VER < 26
-  if (!std::is_constant_evaluated())
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     test_mid(std::ranges::inplace_merge, in, mid);
   }
   test(std::ranges::make_heap, in);
diff --git a/libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp b/libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp
index 32154f9eda8f6..24feab7a0fa38 100644
--- a/libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp
+++ b/libcxx/test/std/algorithms/robust_against_adl_on_new.pass.cpp
@@ -26,10 +26,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
   std::sort(a, a + 4);
   std::sort(a, a + 4, std::less<A>());
   std::partition(a, a + 4, A::isEven);
-#if TEST_STD_VER < 26
-  if (!TEST_IS_CONSTANT_EVALUATED)
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     std::stable_sort(a, a + 4);
     std::stable_sort(a, a + 4, std::less<A>());
     std::stable_partition(a, a + 4, A::isEven);
diff --git a/libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp b/libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp
index e00f123538df8..1b5a57e6d4554 100644
--- a/libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp
+++ b/libcxx/test/std/algorithms/robust_against_proxy_iterators_lifetime_bugs.pass.cpp
@@ -735,18 +735,12 @@ TEST_CONSTEXPR_CXX20 bool test() {
     test(simple_in, [&](I b, I e) { (void) std::shuffle(b, e, rand_gen()); });
   // TODO: unique
   test(simple_in, [&](I b, I e) { (void) std::partition(b, e, is_neg); });
-#if TEST_STD_VER < 26
-  if (!TEST_IS_CONSTANT_EVALUATED)
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     test(simple_in, [&](I b, I e) { (void)std::stable_partition(b, e, is_neg); });
   }
   if (!TEST_IS_CONSTANT_EVALUATED)
     test(sort_test_in, [&](I b, I e) { (void)std::sort(b, e); });
-#if TEST_STD_VER < 26
-  if (!TEST_IS_CONSTANT_EVALUATED)
-#endif
-  {
+  if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
     test(sort_test_in, [&](I b, I e) { (void)std::stable_sort(b, e); });
   }
   // TODO: partial_sort
diff --git a/libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp b/libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp
index b2e30ce88b618..e41efd9b08e29 100644
--- a/libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp
+++ b/libcxx/test/std/algorithms/robust_re_difference_type.compile.pass.cpp
@@ -141,10 +141,7 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
     (void)std::is_sorted(first, last, std::less<void*>());
     (void)std::is_sorted_until(first, last);
     (void)std::is_sorted_until(first, last, std::less<void*>());
-#if TEST_STD_VER < 26
-    if (!TEST_IS_CONSTANT_EVALUATED)
-#endif
-    {
+    if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
       (void)std::inplace_merge(first, mid, last);
       (void)std::inplace_merge(first, mid, last, std::less<void*>());
     }
@@ -245,10 +242,7 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
     (void)std::sort(first, last, std::less<void*>());
     (void)std::sort_heap(first, last);
     (void)std::sort_heap(first, last, std::less<void*>());
-#if TEST_STD_VER < 26
-    if (!TEST_IS_CONSTANT_EVALUATED)
-#endif
-    {
+    if (TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED) {
       (void)std::stable_partition(first, last, UnaryTrue());
       (void)std::stable_sort(first, last);
       (void)std::stable_sort(first, last, std::less<void*>());
diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index 858bbaa2d6d83..f4c4e5d7eee0a 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -148,6 +148,12 @@
 # define TEST_IS_CONSTANT_EVALUATED false
 #endif
 
+#if TEST_STD_VER >= 26
+#  define TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED true
+#else
+#  define TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
+#endif
+
 #if TEST_STD_VER >= 23
 #  define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED true
 #else

>From 853d6c1c5ed6eb2574dbbc52b8cf82f31f794cd3 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sun, 23 Mar 2025 23:08:45 +0800
Subject: [PATCH 2/2] Sort macros in increasing order

---
 libcxx/test/support/test_macros.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index f4c4e5d7eee0a..93dbbaeeeda96 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -148,10 +148,10 @@
 # define TEST_IS_CONSTANT_EVALUATED false
 #endif
 
-#if TEST_STD_VER >= 26
-#  define TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED true
+#if TEST_STD_VER >= 20
+#  define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED true
 #else
-#  define TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
+#  define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
 #endif
 
 #if TEST_STD_VER >= 23
@@ -160,10 +160,10 @@
 #  define TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
 #endif
 
-#if TEST_STD_VER >= 20
-#  define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED true
+#if TEST_STD_VER >= 26
+#  define TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED true
 #else
-#  define TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
+#  define TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED (!TEST_IS_CONSTANT_EVALUATED)
 #endif
 
 #if TEST_STD_VER >= 14



More information about the libcxx-commits mailing list