aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorkosak <kosak@google.com>2014-01-29 07:29:19 +0000
committerkosak <kosak@google.com>2014-01-29 07:29:19 +0000
commit41a8bc67ab7e7a81735e9d560f54d8d130dcc3ab (patch)
treeb604cd1d242d6f9cd70b2640c3f7dc4ea1783bdb /include
parent35956659eaaafd4b356acfbabcb48c183d957ff4 (diff)
downloadgoogletest-41a8bc67ab7e7a81735e9d560f54d8d130dcc3ab.tar.gz
googletest-41a8bc67ab7e7a81735e9d560f54d8d130dcc3ab.tar.bz2
googletest-41a8bc67ab7e7a81735e9d560f54d8d130dcc3ab.zip
Suppress "Conditional expression is constant" warning on Visual Studio.
Diffstat (limited to 'include')
-rw-r--r--include/gtest/gtest-printers.h2
-rw-r--r--include/gtest/internal/gtest-port.h25
2 files changed, 27 insertions, 0 deletions
diff --git a/include/gtest/gtest-printers.h b/include/gtest/gtest-printers.h
index 8ce52b60..852d44a7 100644
--- a/include/gtest/gtest-printers.h
+++ b/include/gtest/gtest-printers.h
@@ -835,7 +835,9 @@ struct TuplePrefixPrinter {
template <typename Tuple>
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
+ GTEST_INTENTIONAL_CONST_COND_PUSH_
if (N > 1) {
+ GTEST_INTENTIONAL_CONST_COND_POP_
*os << ", ";
}
UniversalPrinter<
diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h
index 4bc1e690..a1176760 100644
--- a/include/gtest/internal/gtest-port.h
+++ b/include/gtest/internal/gtest-port.h
@@ -197,6 +197,10 @@
// GTEST_DISALLOW_ASSIGN_ - disables 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_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:
//
@@ -834,6 +838,25 @@ using ::std::tuple_size;
# define GTEST_MOVE_(x) x
#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
// Handling. This is supported by several Windows compilers but generally
// 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
// optimized build at run-time, as it will be optimized away
// completely.
+ GTEST_INTENTIONAL_CONST_COND_PUSH_
if (false) {
+ GTEST_INTENTIONAL_CONST_COND_POP_
const To to = NULL;
::testing::internal::ImplicitCast_<From*>(to);
}