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
This commit is contained in:
Marco Trevisan (Treviño) 2022-11-22 17:30:13 +01:00
parent ad755e7489
commit 5ff02aa5f9

View File

@ -1157,7 +1157,11 @@
# endif
#elif defined (_MSC_VER)
/* Use MSVC specific syntax. */
# 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. */
# 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