C11 supports two-arg _Static_assert keyword
C++11 supports two-arg static_assert keyword
C++17 supports one-arg static_assert keyword
C23 supports one-arg static_assert keyword

So when possible expand _STATIC_ASSERT macro to the suitable C/C++ keyword.
---
 mingw-w64-headers/crt/crtdbg.h | 8 +++++++-
 mingw-w64-headers/crt/malloc.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-headers/crt/crtdbg.h b/mingw-w64-headers/crt/crtdbg.h
index e24d5053bb8d..2fa419e9e89d 100644
--- a/mingw-w64-headers/crt/crtdbg.h
+++ b/mingw-w64-headers/crt/crtdbg.h
@@ -94,7 +94,13 @@ extern "C" {
   } _CrtMemState;
 
 #ifndef _STATIC_ASSERT
-#if defined(_MSC_VER)
+#if (defined(__cpp_static_assert) && __cpp_static_assert >= 201411L) || 
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
+#define _STATIC_ASSERT(expr) static_assert(expr)
+#elif defined(__cpp_static_assert)
+#define _STATIC_ASSERT(expr) static_assert(expr, #expr)
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#define _STATIC_ASSERT(expr) _Static_assert(expr, #expr)
+#elif defined(_MSC_VER)
 #define _STATIC_ASSERT(expr) typedef char __static_assert_t[(expr)]
 #else
 #define _STATIC_ASSERT(expr) extern void __static_assert_t(int [(expr)?1:-1])
diff --git a/mingw-w64-headers/crt/malloc.h b/mingw-w64-headers/crt/malloc.h
index b08f30423a20..d02f3ee7bf5c 100644
--- a/mingw-w64-headers/crt/malloc.h
+++ b/mingw-w64-headers/crt/malloc.h
@@ -21,7 +21,13 @@ extern "C" {
 #endif
 
 #ifndef _STATIC_ASSERT
-#if defined(_MSC_VER)
+#if (defined(__cpp_static_assert) && __cpp_static_assert >= 201411L) || 
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
+#define _STATIC_ASSERT(expr) static_assert(expr)
+#elif defined(__cpp_static_assert)
+#define _STATIC_ASSERT(expr) static_assert(expr, #expr)
+#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+#define _STATIC_ASSERT(expr) _Static_assert(expr, #expr)
+#elif defined(_MSC_VER)
 #define _STATIC_ASSERT(expr) typedef char __static_assert_t[(expr)]
 #else
 #define _STATIC_ASSERT(expr) extern void __static_assert_t(int [(expr)?1:-1])
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to