STL_MSFT created this revision. STL_MSFT added reviewers: EricWF, mclow.lists. STL_MSFT added a subscriber: cfe-commits.
[libcxx] [test] Fix MSVC warning C4127 "conditional expression is constant". MSVC has a compiler warning (enabled at /https://reviews.llvm.org/W4) that's potentially useful, although slightly annoying to library devs who know what they're doing. In the latest version of the compiler, the warning is suppressed when the compiler sees simple tests like "if (name_of_thing)", so extracting comparison expressions into named constants is a workaround. This is useful for ensuring that libraries are C4127-clean. https://reviews.llvm.org/D28592 Files: test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp test/std/utilities/function.objects/unord.hash/enum.pass.cpp test/std/utilities/function.objects/unord.hash/integral.pass.cpp test/std/utilities/template.bitset/bitset.members/all.pass.cpp test/std/utilities/template.bitset/bitset.members/any.pass.cpp test/std/utilities/template.bitset/bitset.members/index.pass.cpp test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp test/std/utilities/template.bitset/bitset.members/none.pass.cpp test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp
Index: test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp =================================================================== --- test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp +++ test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp @@ -36,7 +36,8 @@ const std::bitset<N> v1 = make_bitset<N>(); std::bitset<N> v2 = v1; assert(v1 == v2); - if (N > 0) + const bool greater_than_0 = N > 0; + if (greater_than_0) { v2[N/2].flip(); assert(v1 != v2); Index: test/std/utilities/template.bitset/bitset.members/none.pass.cpp =================================================================== --- test/std/utilities/template.bitset/bitset.members/none.pass.cpp +++ test/std/utilities/template.bitset/bitset.members/none.pass.cpp @@ -20,7 +20,8 @@ assert(v.none() == true); v.set(); assert(v.none() == (N == 0)); - if (N > 1) + const bool greater_than_1 = N > 1; + if (greater_than_1) { v[N/2] = false; assert(v.none() == false); Index: test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp =================================================================== --- test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp +++ test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp @@ -31,7 +31,8 @@ void test_index_const() { const std::bitset<N> v1 = make_bitset<N>(); - if (N > 0) + const bool greater_than_0 = N > 0; + if (greater_than_0) { assert(v1[N/2] == v1.test(N/2)); } Index: test/std/utilities/template.bitset/bitset.members/index.pass.cpp =================================================================== --- test/std/utilities/template.bitset/bitset.members/index.pass.cpp +++ test/std/utilities/template.bitset/bitset.members/index.pass.cpp @@ -31,7 +31,8 @@ void test_index_const() { std::bitset<N> v1 = make_bitset<N>(); - if (N > 0) + const bool greater_than_0 = N > 0; + if (greater_than_0) { assert(v1[N/2] == v1.test(N/2)); typename std::bitset<N>::reference r = v1[N/2]; Index: test/std/utilities/template.bitset/bitset.members/any.pass.cpp =================================================================== --- test/std/utilities/template.bitset/bitset.members/any.pass.cpp +++ test/std/utilities/template.bitset/bitset.members/any.pass.cpp @@ -20,7 +20,8 @@ assert(v.any() == false); v.set(); assert(v.any() == (N != 0)); - if (N > 1) + const bool greater_than_1 = N > 1; + if (greater_than_1) { v[N/2] = false; assert(v.any() == true); Index: test/std/utilities/template.bitset/bitset.members/all.pass.cpp =================================================================== --- test/std/utilities/template.bitset/bitset.members/all.pass.cpp +++ test/std/utilities/template.bitset/bitset.members/all.pass.cpp @@ -20,7 +20,8 @@ assert(v.all() == (N == 0)); v.set(); assert(v.all() == true); - if (N > 1) + const bool greater_than_1 = N > 1; + if (greater_than_1) { v[N/2] = false; assert(v.all() == false); Index: test/std/utilities/function.objects/unord.hash/integral.pass.cpp =================================================================== --- test/std/utilities/function.objects/unord.hash/integral.pass.cpp +++ test/std/utilities/function.objects/unord.hash/integral.pass.cpp @@ -36,7 +36,8 @@ for (int i = 0; i <= 5; ++i) { T t(static_cast<T>(i)); - if (sizeof(T) <= sizeof(std::size_t)) + const bool small = sizeof(T) <= sizeof(std::size_t); + if (small) { const std::size_t result = h(t); LIBCPP_ASSERT(result == static_cast<size_t>(t)); Index: test/std/utilities/function.objects/unord.hash/enum.pass.cpp =================================================================== --- test/std/utilities/function.objects/unord.hash/enum.pass.cpp +++ test/std/utilities/function.objects/unord.hash/enum.pass.cpp @@ -43,7 +43,8 @@ for (int i = 0; i <= 5; ++i) { T t(static_cast<T> (i)); - if (sizeof(T) <= sizeof(std::size_t)) + const bool small = sizeof(T) <= sizeof(std::size_t); + if (small) assert(h1(t) == h2(static_cast<under_type>(i))); } } Index: test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp =================================================================== --- test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp +++ test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/minus1.pass.cpp @@ -66,11 +66,15 @@ test_octal<uint64_t>("1777777777777777777777"); test_octal< int64_t>("1777777777777777777777"); test_octal<uint64_t>("1777777777777777777777"); - if (sizeof(long) == sizeof(int64_t)) { + + const bool long_is_64 = sizeof(long) == sizeof(int64_t); + const bool long_long_is_64 = sizeof(long long) == sizeof(int64_t); + + if (long_is_64) { test_octal< unsigned long>("1777777777777777777777"); test_octal< long>("1777777777777777777777"); } - if (sizeof(long long) == sizeof(int64_t)) { + if (long_long_is_64) { test_octal< unsigned long long>("1777777777777777777777"); test_octal< long long>("1777777777777777777777"); } @@ -81,11 +85,11 @@ test_dec< int32_t>( "-1"); test_dec<uint64_t>("18446744073709551615"); test_dec< int64_t>( "-1"); - if (sizeof(long) == sizeof(int64_t)) { + if (long_is_64) { test_dec<unsigned long>("18446744073709551615"); test_dec< long>( "-1"); } - if (sizeof(long long) == sizeof(int64_t)) { + if (long_long_is_64) { test_dec<unsigned long long>("18446744073709551615"); test_dec< long long>( "-1"); } @@ -96,11 +100,11 @@ test_hex< int32_t>( "FFFFFFFF"); test_hex<uint64_t>("FFFFFFFFFFFFFFFF"); test_hex< int64_t>("FFFFFFFFFFFFFFFF"); - if (sizeof(long) == sizeof(int64_t)) { + if (long_is_64) { test_hex<unsigned long>("FFFFFFFFFFFFFFFF"); test_hex< long>("FFFFFFFFFFFFFFFF"); } - if (sizeof(long long) == sizeof(int64_t)) { + if (long_long_is_64) { test_hex<unsigned long long>("FFFFFFFFFFFFFFFF"); test_hex< long long>("FFFFFFFFFFFFFFFF"); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits