From: Ivan Maidanski Date: Wed, 20 Jun 2018 08:52:33 +0000 (+0300) Subject: Really use C11 static_assert if available (GCC/Clang/MSVC) X-Git-Tag: v8.0.0~102 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f77fc9257eb429982fbe36a7ba044f7b5d46bbaa;p=gc Really use C11 static_assert if available (GCC/Clang/MSVC) (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 ""). --- diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 40bc0d37..823d2bfd 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -745,6 +745,10 @@ EXTERN_C_END #include +#if __STDC_VERSION__ >= 201112L +# include /* 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) */