Skip to content

Commit 1c7607e

Browse files
[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 <[email protected]>
1 parent 10aed27 commit 1c7607e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

libcxx/test/std/containers/sequences/array/array.cons/initialization.pass.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ struct test_initialization {
2828
// Before C++20, default initialization doesn't work inside constexpr for
2929
// trivially default constructible types. This only apply to non-empty arrays,
3030
// since empty arrays don't hold an element of type T.
31-
if (TEST_STD_AT_LEAST_20_OR_RUNTIME_EVALUATED || !std::is_trivially_default_constructible<T>::value) {
32-
std::array<T, 1> a1; (void)a1;
33-
std::array<T, 2> a2; (void)a2;
34-
std::array<T, 3> a3; (void)a3;
31+
#if TEST_STD_VER < 20
32+
if (!(TEST_IS_CONSTANT_EVALUATED && std::is_trivially_default_constructible<T>::value))
33+
#endif
34+
{
35+
std::array<T, 1> a1;
36+
(void)a1;
37+
std::array<T, 2> a2;
38+
(void)a2;
39+
std::array<T, 3> a3;
40+
(void)a3;
3541
}
3642

3743
std::array<NoDefault, 0> nodefault; (void)nodefault;

0 commit comments

Comments
 (0)