diff options
author | Stephan T. Lavavej <stl@exchange.microsoft.com> | 2017-01-18 23:09:56 +0300 |
---|---|---|
committer | Stephan T. Lavavej <stl@exchange.microsoft.com> | 2017-01-18 23:09:56 +0300 |
commit | 3d26ee29215b0e192245e5dabbda825afd3088be (patch) | |
tree | 1a4aa716ecd5132d3920146c472416015b8d25df /libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp | |
parent | 20a00933fbf52ef4492692850326b07ebee8608e (diff) |
[libcxx] [test] Fix MSVC warnings C4127 and C6326 about constants.
MSVC has compiler warnings C4127 "conditional expression is constant" (enabled
by /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.
Fixes D28837.
llvm-svn: 292432
Diffstat (limited to 'libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp')
-rw-r--r-- | libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp index 27d8480d10cf..a2c9df6b4a22 100644 --- a/libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp +++ b/libcxx/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp @@ -11,6 +11,7 @@ #include <bitset> #include <algorithm> +#include <type_traits> #include <climits> #include <cassert> @@ -18,8 +19,9 @@ template <std::size_t N> 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<bool, M == 0>::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<unsigned long long>(1, max), std::min<unsigned long long>(2, max), |