[glib] glib/gmacros.h: Fix build on C++ mode in Visual Studio



commit 2ca496a2e79bf4d9832e9f788f09ed4fee6e1ff7
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed May 4 00:27:32 2016 +0800

    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

 glib/gmacros.h |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 4570d25..9113221 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".
  */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]