[glib/clang-cl-improvements: 33/33] gmacros.h: Improve check for C _Static_assert
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/clang-cl-improvements: 33/33] gmacros.h: Improve check for C _Static_assert
- Date: Tue, 30 Mar 2021 08:45:20 +0000 (UTC)
commit f801c84c52c9da24652e228d306d0ad82522ede9
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Tue Mar 30 16:40:41 2021 +0800
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.
glib/gmacros.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/glib/gmacros.h b/glib/gmacros.h
index 666db5790..3466b268c 100644
--- a/glib/gmacros.h
+++ b/glib/gmacros.h
@@ -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)) || \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]