diff options
author | Albert Astals Cid <aacid@kde.org> | 2023-04-01 11:35:25 +0200 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2023-04-01 11:35:25 +0200 |
commit | 925d2b3b1f631579cc7c8bd09a69f7d49d289148 (patch) | |
tree | d69aefb2e645202ccc16490a8ed529917c754ae8 /glib/gmacros.h | |
parent | 4263cd8cbb34da49a5e7eb9306d617b86e4bc4ab (diff) | |
download | glib-925d2b3b1f631579cc7c8bd09a69f7d49d289148.tar.gz |
Make clang++ happier when using G_STATIC_ASSERT
clang++ says it supports _Static_assert but then will
complain that it's a C11 extension and that you should not use
it in C++ code (which imho is fair enough)
So try to detect a C++ compiler first and then the C compiler,
similarly to what is done for the G_NORETURN case
Diffstat (limited to 'glib/gmacros.h')
-rw-r--r-- | glib/gmacros.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/glib/gmacros.h b/glib/gmacros.h index 30dc03fdb..02ed33417 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -863,18 +863,18 @@ #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 (G_C_STD_CHECK_VERSION (11) || \ +#if G_CXX_STD_CHECK_VERSION (11) +#define G_STATIC_ASSERT(expr) static_assert (expr, "Expression evaluates to false") +#elif (G_C_STD_CHECK_VERSION (11) || \ 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 G_CXX_STD_CHECK_VERSION (11) -#define G_STATIC_ASSERT(expr) static_assert (expr, "Expression evaluates to false") #else #ifdef __COUNTER__ #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED #else #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED #endif -#endif /* G_C_STD_CHECK_VERSION (11) */ +#endif /* G_CXX_STD_CHECK_VERSION (11) */ #define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1])) #endif /* !__GI_SCANNER__ */ |