Reduce compiler warnings on Windows and MacOSX
author <shinichiro.hamaji@gmail.com> <>
Thu, 12 Jul 2012 06:37:47 +0000 (06:37 +0000)
committer <shinichiro.hamaji@gmail.com> <>
Thu, 12 Jul 2012 06:37:47 +0000 (06:37 +0000)
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
src/glog/logging.h.in
src/windows/glog/logging.h
src/windows/port.h

index 0115875..eb3b62f 100644 (file)
 #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
index 4799ea8..ca886b2 100644 (file)
 #   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_
index 25b42c1..cc15b15 100755 (executable)
 #   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_
index 46f1b10..c9be748 100755 (executable)
 
 #ifdef _WIN32
 
+#ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN  /* We always want minimal includes */
+#endif
+
 #include <windows.h>
 #include <winsock.h>         /* for gethostname */
 #include <io.h>              /* because we so often use open/close/etc */