Commit 4f6088bc authored by 's avatar

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
parent 7c613d61
...@@ -162,7 +162,11 @@ ...@@ -162,7 +162,11 @@
#undef VERSION #undef VERSION
/* Stops putting the code inside the Google namespace */ /* Stops putting the code inside the Google namespace */
#ifndef _END_GOOGLE_NAMESPACE_
#undef _END_GOOGLE_NAMESPACE_ #undef _END_GOOGLE_NAMESPACE_
#endif
/* Puts following code inside the Google namespace */ /* Puts following code inside the Google namespace */
#ifndef _START_GOOGLE_NAMESPACE_
#undef _START_GOOGLE_NAMESPACE_ #undef _START_GOOGLE_NAMESPACE_
#endif
...@@ -61,6 +61,14 @@ ...@@ -61,6 +61,14 @@
# define GOOGLE_GLOG_DLL_DECL # define GOOGLE_GLOG_DLL_DECL
# endif # endif
#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, // We care a lot about number of bits things take up. Unfortunately,
// systems define their bit-specific ints in a lot of different ways. // systems define their bit-specific ints in a lot of different ways.
...@@ -941,52 +949,63 @@ const LogSeverity GLOG_0 = GLOG_ERROR; ...@@ -941,52 +949,63 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
#define DLOG_ASSERT(condition) \ #define DLOG_ASSERT(condition) \
true ? (void) 0 : LOG_ASSERT(condition) true ? (void) 0 : LOG_ASSERT(condition)
// MSVC warning C4127: conditional expression is constant
#define DCHECK(condition) \ #define DCHECK(condition) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK(condition) GLOG_MSVC_POP_WARNING() CHECK(condition)
#define DCHECK_EQ(val1, val2) \ #define DCHECK_EQ(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_EQ(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2)
#define DCHECK_NE(val1, val2) \ #define DCHECK_NE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_NE(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2)
#define DCHECK_LE(val1, val2) \ #define DCHECK_LE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_LE(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2)
#define DCHECK_LT(val1, val2) \ #define DCHECK_LT(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_LT(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2)
#define DCHECK_GE(val1, val2) \ #define DCHECK_GE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_GE(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2)
#define DCHECK_GT(val1, val2) \ #define DCHECK_GT(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_GT(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2)
#define DCHECK_NOTNULL(val) (val) #define DCHECK_NOTNULL(val) (val)
#define DCHECK_STREQ(str1, str2) \ #define DCHECK_STREQ(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_STREQ(str1, str2) GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2)
#define DCHECK_STRCASEEQ(str1, str2) \ #define DCHECK_STRCASEEQ(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_STRCASEEQ(str1, str2) GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2)
#define DCHECK_STRNE(str1, str2) \ #define DCHECK_STRNE(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_STRNE(str1, str2) GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2)
#define DCHECK_STRCASENE(str1, str2) \ #define DCHECK_STRCASENE(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_STRCASENE(str1, str2) GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2)
#endif // NDEBUG #endif // NDEBUG
...@@ -1525,4 +1544,7 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureWriter( ...@@ -1525,4 +1544,7 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureWriter(
@ac_google_end_namespace@ @ac_google_end_namespace@
#undef GLOG_MSVC_PUSH_DISABLE_WARNING
#undef GLOG_MSVC_POP_WARNING
#endif // _LOGGING_H_ #endif // _LOGGING_H_
...@@ -65,6 +65,14 @@ ...@@ -65,6 +65,14 @@
# define GOOGLE_GLOG_DLL_DECL # define GOOGLE_GLOG_DLL_DECL
# endif # endif
#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, // We care a lot about number of bits things take up. Unfortunately,
// systems define their bit-specific ints in a lot of different ways. // systems define their bit-specific ints in a lot of different ways.
...@@ -945,52 +953,63 @@ const LogSeverity GLOG_0 = GLOG_ERROR; ...@@ -945,52 +953,63 @@ const LogSeverity GLOG_0 = GLOG_ERROR;
#define DLOG_ASSERT(condition) \ #define DLOG_ASSERT(condition) \
true ? (void) 0 : LOG_ASSERT(condition) true ? (void) 0 : LOG_ASSERT(condition)
// MSVC warning C4127: conditional expression is constant
#define DCHECK(condition) \ #define DCHECK(condition) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK(condition) GLOG_MSVC_POP_WARNING() CHECK(condition)
#define DCHECK_EQ(val1, val2) \ #define DCHECK_EQ(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_EQ(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_EQ(val1, val2)
#define DCHECK_NE(val1, val2) \ #define DCHECK_NE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_NE(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_NE(val1, val2)
#define DCHECK_LE(val1, val2) \ #define DCHECK_LE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_LE(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_LE(val1, val2)
#define DCHECK_LT(val1, val2) \ #define DCHECK_LT(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_LT(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_LT(val1, val2)
#define DCHECK_GE(val1, val2) \ #define DCHECK_GE(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_GE(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_GE(val1, val2)
#define DCHECK_GT(val1, val2) \ #define DCHECK_GT(val1, val2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_GT(val1, val2) GLOG_MSVC_POP_WARNING() CHECK_GT(val1, val2)
#define DCHECK_NOTNULL(val) (val) #define DCHECK_NOTNULL(val) (val)
#define DCHECK_STREQ(str1, str2) \ #define DCHECK_STREQ(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_STREQ(str1, str2) GLOG_MSVC_POP_WARNING() CHECK_STREQ(str1, str2)
#define DCHECK_STRCASEEQ(str1, str2) \ #define DCHECK_STRCASEEQ(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_STRCASEEQ(str1, str2) GLOG_MSVC_POP_WARNING() CHECK_STRCASEEQ(str1, str2)
#define DCHECK_STRNE(str1, str2) \ #define DCHECK_STRNE(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_STRNE(str1, str2) GLOG_MSVC_POP_WARNING() CHECK_STRNE(str1, str2)
#define DCHECK_STRCASENE(str1, str2) \ #define DCHECK_STRCASENE(str1, str2) \
GLOG_MSVC_PUSH_DISABLE_WARNING(4127) \
while (false) \ while (false) \
CHECK_STRCASENE(str1, str2) GLOG_MSVC_POP_WARNING() CHECK_STRCASENE(str1, str2)
#endif // NDEBUG #endif // NDEBUG
...@@ -1529,4 +1548,7 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureWriter( ...@@ -1529,4 +1548,7 @@ GOOGLE_GLOG_DLL_DECL void InstallFailureWriter(
} }
#undef GLOG_MSVC_PUSH_DISABLE_WARNING
#undef GLOG_MSVC_POP_WARNING
#endif // _LOGGING_H_ #endif // _LOGGING_H_
...@@ -45,7 +45,10 @@ ...@@ -45,7 +45,10 @@
#ifdef _WIN32 #ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN /* We always want minimal includes */ #define WIN32_LEAN_AND_MEAN /* We always want minimal includes */
#endif
#include <windows.h> #include <windows.h>
#include <winsock.h> /* for gethostname */ #include <winsock.h> /* for gethostname */
#include <io.h> /* because we so often use open/close/etc */ #include <io.h> /* because we so often use open/close/etc */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment