From 5ff02aa5f9aa445d15241459ddb529a59e3c71b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 22 Nov 2022 17:30:13 +0100 Subject: [PATCH] gmacros: Use C++ namespaces attribute specifier sequences for msvc As we do already for GNU compilers, when using C++ we should use attribute sequences with msvc namespace. This is not supported by msvc versions earlier than 2019 16.7 according to [1], and thus we need to check if `_MSC_VER` is at least 1927 [2]. See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2895#note_1572952 [1] https://www.codetd.com/en/article/11761480 [2] https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170&viewFallbackFrom=vs-2019#feedback --- glib/gmacros.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/glib/gmacros.h b/glib/gmacros.h index 9f69428f3..da3611de0 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -1157,7 +1157,11 @@ # endif #elif defined (_MSC_VER) /* Use MSVC specific syntax. */ -# define G_ALWAYS_INLINE __forceinline +# if G_CXX_STD_CHECK_VERSION (11) && _MSC_VER >= 1927 +# define G_ALWAYS_INLINE [[msvc::forceinline]] +# else +# define G_ALWAYS_INLINE __forceinline +# endif #else # define G_ALWAYS_INLINE /* empty */ #endif @@ -1197,6 +1201,12 @@ /* Use ISO C++11 syntax when the compiler supports it. */ # if defined (__GNUC__) # define G_NO_INLINE [[gnu::noinline]] +# elif defined (_MSC_VER) +# if _MSC_VER >= 1927 +# define G_NO_INLINE [[msvc::noinline]] +# else +# define G_NO_INLINE __declspec (noinline) +# endif # endif # else # define G_NO_INLINE __attribute__ ((__noinline__)) @@ -1204,7 +1214,11 @@ #elif defined (_MSC_VER) && (1200 <= _MSC_VER) /* Use MSVC specific syntax. */ /* Use ISO C++11 syntax when the compiler supports it. */ -# define G_NO_INLINE __declspec (noinline) +# if G_CXX_STD_CHECK_VERSION (11) && _MSC_VER >= 1927 +# define G_NO_INLINE [[msvc::noinline]] +# else +# define G_NO_INLINE __declspec (noinline) +# endif #else # define G_NO_INLINE /* empty */ #endif