From 4f6088bc72ae56676b1353305a8295ce6e083d70 Mon Sep 17 00:00:00 2001 From: Date: Thu, 12 Jul 2012 06:37:47 +0000 Subject: [PATCH] Reduce compiler warnings on Windows and MacOSX DCHECK* causes "warning C4127: conditional expression is constant". If compiled with -DWIN32_LEAN_AND_MEAN, port.h: warning C4005: 'WIN32_LEAN_AND_MEAN': macro redefinition. On MacOSX, warning: "_END_GOOGLE_NAMESPACE_" redefined warning: "_START_GOOGLE_NAMESPACE_" redefined because config.h is included from base/commandlineflags.h:51 from logging.cc:60 and from utilities.h:81 from logging.cc:32 or so. Contributed by ukai@ git-svn-id: https://google-glog.googlecode.com/svn/trunk@114 eb4d4688-79bd-11dd-afb4-1d65580434c0 --- src/config.h.in | 4 ++++ src/glog/logging.h.in | 46 ++++++++++++++++++++++++++++++++++------------ src/windows/glog/logging.h | 46 ++++++++++++++++++++++++++++++++++------------ src/windows/port.h | 3 +++ 4 files changed, 75 insertions(+), 24 deletions(-) diff --git a/src/config.h.in b/src/config.h.in index 0115875..eb3b62f 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -162,7 +162,11 @@ #undef VERSION /* Stops putting the code inside the Google namespace */ +#ifndef _END_GOOGLE_NAMESPACE_ #undef _END_GOOGLE_NAMESPACE_ +#endif /* Puts following code inside the Google namespace */ +#ifndef _START_GOOGLE_NAMESPACE_ #undef _START_GOOGLE_NAMESPACE_ +#endif diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in index 4799ea8..ca886b2 100644 --- a/src/glog/logging.h.in +++ b/src/glog/logging.h.in @@ -61,6 +61,14 @@ # define GOOGLE_GLOG_DLL_DECL # endif #endif +#if defined(_MSC_VER) +#define GLOG_MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \ + __pragma(warning(disable:n)) +#define GLOG_MSVC_POP_WARNING() __pragma(warning(pop)) +#else +#define GLOG_MSVC_PUSH_DISABLE_WARNING(n) +#define GLOG_MSVC_POP_WARNING() +#endif // We care a lot about number of bits things take up. Unfortunately, // systems define their bit-specific ints in a lot of different ways. @@ -941,52 +949,63 @@ const LogSeverity GLOG_0 = GLOG_ERROR; #define DLOG_ASSERT(condition) \ true ? (void) 0 : LOG_ASSERT(condition) +// MSVC warning C4127: conditional expression is constant #define DCHECK(condition) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK(condition) + GLOG_MSVC_POP_WARNING() CHECK(condition) #define DCHECK_EQ(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_EQ(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2) #define DCHECK_NE(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_NE(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2) #define DCHECK_LE(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_LE(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2) #define DCHECK_LT(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_LT(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2) #define DCHECK_GE(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_GE(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2) #define DCHECK_GT(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_GT(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2) #define DCHECK_NOTNULL(val) (val) #define DCHECK_STREQ(str1, str2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_STREQ(str1, str2) + GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2) #define DCHECK_STRCASEEQ(str1, str2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_STRCASEEQ(str1, str2) + GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2) #define DCHECK_STRNE(str1, str2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_STRNE(str1, str2) + GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2) #define DCHECK_STRCASENE(str1, str2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_STRCASENE(str1, str2) - + GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2) #endif // NDEBUG @@ -1525,4 +1544,7 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureWriter( @ac_google_end_namespace@ +#undef GLOG_MSVC_PUSH_DISABLE_WARNING +#undef GLOG_MSVC_POP_WARNING + #endif // _LOGGING_H_ diff --git a/src/windows/glog/logging.h b/src/windows/glog/logging.h index 25b42c1..cc15b15 100755 --- a/src/windows/glog/logging.h +++ b/src/windows/glog/logging.h @@ -65,6 +65,14 @@ # define GOOGLE_GLOG_DLL_DECL # endif #endif +#if defined(_MSC_VER) +#define GLOG_MSVC_PUSH_DISABLE_WARNING(n) __pragma(warning(push)) \ + __pragma(warning(disable:n)) +#define GLOG_MSVC_POP_WARNING() __pragma(warning(pop)) +#else +#define GLOG_MSVC_PUSH_DISABLE_WARNING(n) +#define GLOG_MSVC_POP_WARNING() +#endif // We care a lot about number of bits things take up. Unfortunately, // systems define their bit-specific ints in a lot of different ways. @@ -945,52 +953,63 @@ const LogSeverity GLOG_0 = GLOG_ERROR; #define DLOG_ASSERT(condition) \ true ? (void) 0 : LOG_ASSERT(condition) +// MSVC warning C4127: conditional expression is constant #define DCHECK(condition) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK(condition) + GLOG_MSVC_POP_WARNING() CHECK(condition) #define DCHECK_EQ(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_EQ(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2) #define DCHECK_NE(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_NE(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2) #define DCHECK_LE(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_LE(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2) #define DCHECK_LT(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_LT(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2) #define DCHECK_GE(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_GE(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2) #define DCHECK_GT(val1, val2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_GT(val1, val2) + GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2) #define DCHECK_NOTNULL(val) (val) #define DCHECK_STREQ(str1, str2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_STREQ(str1, str2) + GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2) #define DCHECK_STRCASEEQ(str1, str2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_STRCASEEQ(str1, str2) + GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2) #define DCHECK_STRNE(str1, str2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_STRNE(str1, str2) + GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2) #define DCHECK_STRCASENE(str1, str2) \ + GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \ while (false) \ - CHECK_STRCASENE(str1, str2) - + GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2) #endif // NDEBUG @@ -1529,4 +1548,7 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureWriter( } +#undef GLOG_MSVC_PUSH_DISABLE_WARNING +#undef GLOG_MSVC_POP_WARNING + #endif // _LOGGING_H_ diff --git a/src/windows/port.h b/src/windows/port.h index 46f1b10..c9be748 100755 --- a/src/windows/port.h +++ b/src/windows/port.h @@ -45,7 +45,10 @@ #ifdef _WIN32 +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN /* We always want minimal includes */ +#endif + #include #include /* for gethostname */ #include /* because we so often use open/close/etc */ -- 2.7.4