[glib/glib-2-42] Avoid warning when using G_STMT_END macro with MSVC
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-42] Avoid warning when using G_STMT_END macro with MSVC
- Date: Wed, 14 Jan 2015 15:26:21 +0000 (UTC)
commit b2c0f526008fa709af84d6e5699d581688365392
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Jan 13 12:44:20 2015 +0100
Avoid warning when using G_STMT_END macro with MSVC
Workaround found on
http://cnicholson.net/2009/03/stupid-c-tricks-dowhile0-and-c4127/
https://bugzilla.gnome.org/show_bug.cgi?id=742851
glib/gmacros.h | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 0bdfa55..7320228 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -279,11 +279,21 @@
* if (x) G_STMT_START { ... } G_STMT_END; else ...
* This intentionally does not use compiler extensions like GCC's '({...})' to
* avoid portability issue or side effects when compiled with different compilers.
+ * MSVC complains about "while(0)": C4127: “Conditional expression is constant”,
+ * so we use __pragma to avoid the warning since the use here is intentional.
*/
#if !(defined (G_STMT_START) && defined (G_STMT_END))
#define G_STMT_START do
+#if defined (_MSC_VER) && (_MSC_VER >= 1500)
+#define G_STMT_END \
+ __pragma(warning(push)) \
+ __pragma(warning(disable:4127)) \
+ while(0) \
+ __pragma(warning(pop))
+#else
#define G_STMT_END while (0)
#endif
+#endif
/* Deprecated -- do not use. */
#ifndef G_DISABLE_DEPRECATED
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]