[glib/clang-cl-improvements] gmacros.h: Improve check for C _Static_assert



commit dd0f162ce97972fc6892541b2fd3b0788e0e1e64
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]