[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.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292432 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Stephan T. Lavavej
2017-01-18 20:09:56 +00:00
parent 0d4bd61d78
commit c3564b92bc
12 changed files with 43 additions and 20 deletions

View File

@@ -23,6 +23,7 @@
#include <sstream>
#include <ios>
#include <type_traits>
#include <cctype>
#include <cstdint>
#include <cassert>
@@ -66,11 +67,15 @@ int main()
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 = std::integral_constant<bool, sizeof(long) == sizeof(int64_t)>::value; // avoid compiler warnings
const bool long_long_is_64 = std::integral_constant<bool, sizeof(long long) == sizeof(int64_t)>::value; // avoid compiler warnings
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 +86,11 @@ int main()
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 +101,11 @@ int main()
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");
}