gmacros.h: Improve check for C _Static_assert

Use the GCC/Clang macros __has_extension() and __has_feature() on
c_static_assert, which is the documented way for GCC/CLang to check for
_Static_assert if C11 mode is not enabled, as suggested by Aleksandr Mezin.

As a result, add a private macro that is defined to be __has_extension if it
exists, otherwise it is considered to be always false.
This commit is contained in:
Chun-wei Fan 2021-03-30 16:40:41 +08:00
parent 7b76995298
commit f801c84c52

View File

@ -276,6 +276,12 @@
#define g_macro__has_builtin(x) 0
#endif
#ifdef __has_extension
#define g_macro__has_extension __has_extension
#else
#define g_macro__has_extension(x) 0
#endif
/**
* G_GNUC_ALLOC_SIZE:
* @x: the index of the argument specifying the allocation size
@ -754,7 +760,8 @@
#ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
#define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
#if !defined(__cplusplus) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L || defined(__clang__))
#if !defined(__cplusplus) && defined(__STDC_VERSION__) && \
(__STDC_VERSION__ >= 201112L || g_macro__has_feature(c_static_assert) || g_macro__has_extension(c_static_assert))
#define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
#elif (defined(__cplusplus) && __cplusplus >= 201103L) || \
(defined(__cplusplus) && defined (_MSC_VER) && (_MSC_VER >= 1600)) || \