From 6a892726d1c12d9c58fca7ab5579b33e572acc85 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Wed, 4 May 2016 00:27:32 +0800 Subject: [PATCH] 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 file 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". */