[libcxx-commits] [libcxx] [libc++][test] Fix MSVC warning C4127 in `array.cons/initialization.pass.cpp` (PR #79793)

Stephan T. Lavavej via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 28 23:39:54 PST 2024


https://github.com/StephanTLavavej updated https://github.com/llvm/llvm-project/pull/79793

>From 9e81886878ea9759a61e1f4154af24cec3150d81 Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Sun, 28 Jan 2024 21:52:10 -0800
Subject: [PATCH 1/2] Fix MSVC warning C4127: conditional expression is
 constant

Testing TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED by itself doesn't
emit this warning, but the condition here is more complicated. I'm
expanding the macro and mechanically simplifying the resulting code.
---
 .../sequences/array/array.cons/initialization.pass.cpp       | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp
index 7991d4738d9699b..acd176cce91d9ed 100644
--- a/libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp
@@ -28,7 +28,10 @@ struct test_initialization {
             // Before C++20, default initialization doesn't work inside constexpr for
             // trivially default constructible types. This only apply to non-empty arrays,
             // since empty arrays don't hold an element of type T.
-            if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED || !std::is_trivially_default_constructible<T>::value) {
+#if TEST_STD_VER < 20
+            if (!TEST_IS_CONSTANT_EVALUATED || !std::is_trivially_default_constructible<T>::value)
+#endif
+            {
                 std::array<T, 1> a1; (void)a1;
                 std::array<T, 2> a2; (void)a2;
                 std::array<T, 3> a3; (void)a3;

>From 797143329788def0e0967dd9a5cb5c052c07402a Mon Sep 17 00:00:00 2001
From: "Stephan T. Lavavej" <stl at nuwen.net>
Date: Sun, 28 Jan 2024 23:39:26 -0800
Subject: [PATCH 2/2] clang-format.

---
 .../sequences/array/array.cons/initialization.pass.cpp   | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp
index acd176cce91d9ed..37d716740a29fa3 100644
--- a/libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp
+++ b/libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp
@@ -32,9 +32,12 @@ struct test_initialization {
             if (!TEST_IS_CONSTANT_EVALUATED || !std::is_trivially_default_constructible<T>::value)
 #endif
             {
-                std::array<T, 1> a1; (void)a1;
-                std::array<T, 2> a2; (void)a2;
-                std::array<T, 3> a3; (void)a3;
+              std::array<T, 1> a1;
+              (void)a1;
+              std::array<T, 2> a2;
+              (void)a2;
+              std::array<T, 3> a3;
+              (void)a3;
             }
 
             std::array<NoDefault, 0> nodefault; (void)nodefault;



More information about the libcxx-commits mailing list