STL_MSFT created this revision.
[libcxx] [test] Fix MSVC warnings C4127 and C6326 about constants.
MSVC has compiler warnings C4127 "conditional expression is constant" (enabled
by /https://reviews.llvm.org/W4) and C6326 "Potential comparison of a constant
with another constant"
(enabled by /analyze). They're potentially useful, although they're slightly
annoying to library devs who know what they're doing. In the latest version of
the compiler, C4127 is suppressed when the compiler sees simple tests like
"if (name_of_thing)", so extracting comparison expressions into named
constants is a workaround. At the same time, using std::integral_constant
avoids C6326, which doesn't look at template arguments.
test/std/containers/sequences/vector.bool/emplace.pass.cpp
Replace 1 == 1 with true, which is the same as far as the library is concerned.
https://reviews.llvm.org/D28837
Files:
test/std/containers/sequences/vector.bool/emplace.pass.cpp
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
test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
Index: test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
===
--- test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
+++ test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp
@@ -11,16 +11,18 @@
#include
#include
+#include
#include
#include
#include
template
void test_to_ulong()
{
const std::size_t M = sizeof(unsigned long) * CHAR_BIT < N ? sizeof(unsigned long) * CHAR_BIT : N;
-const std::size_t X = M == 0 ? sizeof(unsigned long) * CHAR_BIT - 1 : sizeof(unsigned long) * CHAR_BIT - M;
-const std::size_t max = M == 0 ? 0 : std::size_t(std::numeric_limits::max()) >> X;
+const bool is_M_zero = std::integral_constant::value; // avoid compiler warnings
+const std::size_t X = is_M_zero ? sizeof(unsigned long) * CHAR_BIT - 1 : sizeof(unsigned long) * CHAR_BIT - M;
+const std::size_t max = is_M_zero ? 0 : std::size_t(std::numeric_limits::max()) >> X;
std::size_t tests[] = {0,
std::min(1, max),
std::min(2, max),
Index: test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
===
--- test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
+++ test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp
@@ -11,15 +11,17 @@
#include
#include
+#include
#include
#include
template
void test_to_ullong()
{
const std::size_t M = sizeof(unsigned long long) * CHAR_BIT < N ? sizeof(unsigned long long) * CHAR_BIT : N;
-const std::size_t X = M == 0 ? sizeof(unsigned long long) * CHAR_BIT - 1 : sizeof(unsigned long long) * CHAR_BIT - M;
-const unsigned long long max = M == 0 ? 0 : (unsigned long long)(-1) >> X;
+const bool is_M_zero = std::integral_constant::value; // avoid compiler warnings
+const std::size_t X = is_M_zero ? sizeof(unsigned long long) * CHAR_BIT - 1 : sizeof(unsigned long long) * CHAR_BIT - M;
+const unsigned long long max = is_M_zero ? 0 : (unsigned long long)(-1) >> X;
unsigned long long tests[] = {0,
std::min(1, max),
std::min(2, max),
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
@@ -13,6 +13,7 @@
// bool operator!=(const bitset& rhs) const;
#include
+#include
#include
#include
@@ -36,7 +37,8 @@
const std::bitset v1 = make_bitset();
std::bitset v2 = v1;
assert(v1 == v2);
-if (N > 0)
+const bool greater_than_0 = std::integral_constant 0)>::value; // avoid compiler warnings
+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.member