Suppress "Conditional expression is constant" warning on Visual Studio.
This commit is contained in:
parent
35956659ea
commit
41a8bc67ab
|
@ -55,7 +55,7 @@ macro(config_compiler_and_linker)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
# Newlines inside flags variables break CMake's NMake generator.
|
# Newlines inside flags variables break CMake's NMake generator.
|
||||||
# TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds.
|
# TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds.
|
||||||
set(cxx_base_flags "-GS -W4 -WX -wd4127 -wd4251 -wd4275 -nologo -J -Zi")
|
set(cxx_base_flags "-GS -W4 -WX -wd4251 -wd4275 -nologo -J -Zi")
|
||||||
if (MSVC_VERSION LESS 1400) # 1400 is Visual Studio 2005
|
if (MSVC_VERSION LESS 1400) # 1400 is Visual Studio 2005
|
||||||
# Suppress spurious warnings MSVC 7.1 sometimes issues.
|
# Suppress spurious warnings MSVC 7.1 sometimes issues.
|
||||||
# Forcing value to bool.
|
# Forcing value to bool.
|
||||||
|
@ -66,6 +66,15 @@ macro(config_compiler_and_linker)
|
||||||
# Resolved overload was found by argument-dependent lookup.
|
# Resolved overload was found by argument-dependent lookup.
|
||||||
set(cxx_base_flags "${cxx_base_flags} -wd4675")
|
set(cxx_base_flags "${cxx_base_flags} -wd4675")
|
||||||
endif()
|
endif()
|
||||||
|
if (MSVC_VERSION LESS 1500) # 1500 is Visual Studio 2008
|
||||||
|
# Conditional expression is constant.
|
||||||
|
# When compiling with /W4, we get several instances of C4127
|
||||||
|
# (Conditional expression is constant). In our code, we disable that
|
||||||
|
# warning on a case-by-case basis. However, on Visual Studio 2005,
|
||||||
|
# the warning fires on std::list. Therefore on that compiler and earlier,
|
||||||
|
# we disable the warning project-wide.
|
||||||
|
set(cxx_base_flags "${cxx_base_flags} -wd4127")
|
||||||
|
endif()
|
||||||
if (NOT (MSVC_VERSION LESS 1700)) # 1700 is Visual Studio 2012.
|
if (NOT (MSVC_VERSION LESS 1700)) # 1700 is Visual Studio 2012.
|
||||||
# Suppress "unreachable code" warning on VS 2012 and later.
|
# Suppress "unreachable code" warning on VS 2012 and later.
|
||||||
# http://stackoverflow.com/questions/3232669 explains the issue.
|
# http://stackoverflow.com/questions/3232669 explains the issue.
|
||||||
|
|
|
@ -835,7 +835,9 @@ struct TuplePrefixPrinter {
|
||||||
template <typename Tuple>
|
template <typename Tuple>
|
||||||
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
|
||||||
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
|
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
|
||||||
|
GTEST_INTENTIONAL_CONST_COND_PUSH_
|
||||||
if (N > 1) {
|
if (N > 1) {
|
||||||
|
GTEST_INTENTIONAL_CONST_COND_POP_
|
||||||
*os << ", ";
|
*os << ", ";
|
||||||
}
|
}
|
||||||
UniversalPrinter<
|
UniversalPrinter<
|
||||||
|
|
|
@ -197,6 +197,10 @@
|
||||||
// GTEST_DISALLOW_ASSIGN_ - disables operator=.
|
// GTEST_DISALLOW_ASSIGN_ - disables operator=.
|
||||||
// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
|
// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
|
||||||
// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
|
// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
|
||||||
|
// GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is
|
||||||
|
// suppressed (constant conditional).
|
||||||
|
// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127
|
||||||
|
// is suppressed.
|
||||||
//
|
//
|
||||||
// C++11 feature wrappers:
|
// C++11 feature wrappers:
|
||||||
//
|
//
|
||||||
|
@ -834,6 +838,25 @@ using ::std::tuple_size;
|
||||||
# define GTEST_MOVE_(x) x
|
# define GTEST_MOVE_(x) x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// MS C++ compiler emits warning when a conditional expression is compile time
|
||||||
|
// constant. In some contexts this warning is false positive and needs to be
|
||||||
|
// suppressed. Use the following two macros in such cases:
|
||||||
|
//
|
||||||
|
// GTEST_INTENTIONAL_CONST_COND_PUSH_
|
||||||
|
// while (true) {
|
||||||
|
// GTEST_INTENTIONAL_CONST_COND_POP_
|
||||||
|
// }
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# define GTEST_INTENTIONAL_CONST_COND_PUSH_ \
|
||||||
|
__pragma(warning(push)) \
|
||||||
|
__pragma(warning(disable: 4127))
|
||||||
|
# define GTEST_INTENTIONAL_CONST_COND_POP_ \
|
||||||
|
__pragma(warning(pop))
|
||||||
|
#else
|
||||||
|
# define GTEST_INTENTIONAL_CONST_COND_PUSH_
|
||||||
|
# define GTEST_INTENTIONAL_CONST_COND_POP_
|
||||||
|
#endif
|
||||||
|
|
||||||
// Determine whether the compiler supports Microsoft's Structured Exception
|
// Determine whether the compiler supports Microsoft's Structured Exception
|
||||||
// Handling. This is supported by several Windows compilers but generally
|
// Handling. This is supported by several Windows compilers but generally
|
||||||
// does not exist on any other system.
|
// does not exist on any other system.
|
||||||
|
@ -1248,7 +1271,9 @@ inline To DownCast_(From* f) { // so we only accept pointers
|
||||||
// for compile-time type checking, and has no overhead in an
|
// for compile-time type checking, and has no overhead in an
|
||||||
// optimized build at run-time, as it will be optimized away
|
// optimized build at run-time, as it will be optimized away
|
||||||
// completely.
|
// completely.
|
||||||
|
GTEST_INTENTIONAL_CONST_COND_PUSH_
|
||||||
if (false) {
|
if (false) {
|
||||||
|
GTEST_INTENTIONAL_CONST_COND_POP_
|
||||||
const To to = NULL;
|
const To to = NULL;
|
||||||
::testing::internal::ImplicitCast_<From*>(to);
|
::testing::internal::ImplicitCast_<From*>(to);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,9 @@ TEST_F(PrematureExitDeathTest, FileExistsDuringExecutionOfDeathTest) {
|
||||||
// Tests that TEST_PREMATURE_EXIT_FILE is set where it's expected to
|
// Tests that TEST_PREMATURE_EXIT_FILE is set where it's expected to
|
||||||
// be set.
|
// be set.
|
||||||
TEST_F(PrematureExitTest, TestPrematureExitFileEnvVarIsSet) {
|
TEST_F(PrematureExitTest, TestPrematureExitFileEnvVarIsSet) {
|
||||||
|
GTEST_INTENTIONAL_CONST_COND_PUSH_
|
||||||
if (kTestPrematureExitFileEnvVarShouldBeSet) {
|
if (kTestPrematureExitFileEnvVarShouldBeSet) {
|
||||||
|
GTEST_INTENTIONAL_CONST_COND_POP_
|
||||||
const char* const filepath = GetEnv("TEST_PREMATURE_EXIT_FILE");
|
const char* const filepath = GetEnv("TEST_PREMATURE_EXIT_FILE");
|
||||||
ASSERT_TRUE(filepath != NULL);
|
ASSERT_TRUE(filepath != NULL);
|
||||||
ASSERT_NE(*filepath, '\0');
|
ASSERT_NE(*filepath, '\0');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user