Really use C11 static_assert if available (GCC/Clang/MSVC)
authorIvan Maidanski <ivmai@mail.ru>
Wed, 20 Jun 2018 08:52:33 +0000 (11:52 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 20 Jun 2018 08:52:33 +0000 (11:52 +0300)
(fix of commit 7d34f4e5c)

Issue #223 (bdwgc).

Improve static assertion message as well.

* include/private/gc_priv.h [__STDC_VERSION__>=201112L]: Include
assert.h (to have static_assert defined).
* include/private/gc_priv.h [_MSC_VER>=1700] (GC_STATIC_ASSERT): Define
as static_assert.
* include/private/gc_priv.h [static_assert && __STDC_VERSION__>=201112L]
(GC_STATIC_ASSERT): Pass #expr as the 2nd argument to static_assert
(instead of "").

include/private/gc_priv.h

index 40bc0d3..823d2bf 100644 (file)
@@ -745,6 +745,10 @@ EXTERN_C_END
 
 #include <setjmp.h>
 
+#if __STDC_VERSION__ >= 201112L
+# include <assert.h> /* for static_assert */
+#endif
+
 EXTERN_C_BEGIN
 
 /*********************************/
@@ -2484,8 +2488,11 @@ GC_INNER void *GC_store_debug_info_inner(void *p, word sz, const char *str,
 #endif
 
 /* Check a compile time assertion at compile time.      */
-#if defined(static_assert) && (__STDC_VERSION__ >= 201112L)
-# define GC_STATIC_ASSERT(expr) static_assert(expr, "")
+#if _MSC_VER >= 1700
+# define GC_STATIC_ASSERT(expr) \
+                static_assert(expr, "static assertion failed: " #expr)
+#elif defined(static_assert) && __STDC_VERSION__ >= 201112L
+# define GC_STATIC_ASSERT(expr) static_assert(expr, #expr)
 #elif defined(mips) && !defined(__GNUC__)
 /* DOB: MIPSPro C gets an internal error taking the sizeof an array type.
    This code works correctly (ugliness is to avoid "unused var" warnings) */