[libcxx-commits] [libcxx] 1c7607e - [libc++][test] Fix MSVC warning C4127 in `array.cons/initialization.pass.cpp` (#79793)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Mar 9 02:32:02 PST 2024
Author: Stephan T. Lavavej
Date: 2024-03-09T02:31:58-08:00
New Revision: 1c7607e8ee6ec4ca3abce1561dd39a98d4efac96
URL: https://github.com/llvm/llvm-project/commit/1c7607e8ee6ec4ca3abce1561dd39a98d4efac96
DIFF: https://github.com/llvm/llvm-project/commit/1c7607e8ee6ec4ca3abce1561dd39a98d4efac96.diff
LOG: [libc++][test] Fix MSVC warning C4127 in `array.cons/initialization.pass.cpp` (#79793)
This fixes 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.
(Yeah, this warning is often annoying, and I introduced
`TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED` to avoid this warning
elsewhere, so it's disappointing that it doesn't make the compiler happy
here. If this change is undesirable, I can replace it with
`ADDITIONAL_COMPILE_FLAGS(cl-style-warnings)`, but ideally I'd like to
avoid having to suppress it.)
---------
Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>
Added:
Modified:
libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp
Removed:
################################################################################
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 7991d4738d9699..a23211f5464d6f 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,10 +28,16 @@ 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) {
- std::array<T, 1> a1; (void)a1;
- std::array<T, 2> a2; (void)a2;
- std::array<T, 3> a3; (void)a3;
+#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;
}
std::array<NoDefault, 0> nodefault; (void)nodefault;
More information about the libcxx-commits
mailing list