summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2016-05-04 00:27:32 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2016-05-05 00:45:14 +0800
commit6a892726d1c12d9c58fca7ab5579b33e572acc85 (patch)
tree3491ffa4e591613994ca54707b13d8cb18639e0d
parentbb11e01de7b19db80dd9ce1915bb258a9ea6cd9c (diff)
downloadglib-6a892726d1c12d9c58fca7ab5579b33e572acc85.tar.gz
glib/gmacros.h: Fix build on C++ mode in Visual Studio
Later Visual Studio versions does not allow one to define known keywords, even if they are actually not known to the compiler. Avoid this issue by checking more conditions before we define inline as __inline: -We are not building under C++ mode. -We are on Visual Studio 2013 or earlier. Where both of these conditions need to hold true. https://bugzilla.gnome.org/show_bug.cgi?id=765990
-rw-r--r--glib/gmacros.h27
1 files changed, 21 insertions, 6 deletions
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 4570d2524..91132217b 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -54,16 +54,31 @@
#endif
/* Every compiler that we target supports inlining, but some of them may
- * complain about it if we don't say "__inline". If we have C99, then
- * we can use "inline" directly. Otherwise, we say "__inline" to avoid
- * the warning.
+ * complain about it if we don't say "__inline". If we have C99, or if
+ * we are using C++, then we can use "inline" directly. Unfortunately
+ * Visual Studio does not support __STDC_VERSION__, so we need to check
+ * whether we are on Visual Studio 2013 or earlier to see that we need to
+ * say "__inline" in C mode.
+ * Otherwise, we say "__inline" to avoid the warning.
*/
#define G_CAN_INLINE
-#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199900)
-#undef inline
-#define inline __inline
+#ifndef __cplusplus
+# ifdef _MSC_VER
+# if (_MSC_VER < 1900)
+# define G_INLINE_DEFINE_NEEDED
+# endif
+# elif !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199900)
+# define G_INLINE_DEFINE_NEEDED
+# endif
#endif
+#ifdef G_INLINE_DEFINE_NEEDED
+# undef inline
+# define inline __inline
+#endif
+
+#undef G_INLINE_DEFINE_NEEDED
+
/* For historical reasons we need to continue to support those who
* define G_IMPLEMENT_INLINES to mean "don't implement this here".
*/