Better checks for static_assert availability

When not in c++ or c11 mode:
- check for _Static_assert support in clang with __has_extension
- gcc implements _Static_assert starting with 4.6.0
- as a fallback, use a forward decl instead of ((void)0) so that
  static_assert can be used at file scope (scope issue pointed out by
  guenther@)

ok jsg@
This commit is contained in:
jca 2020-01-30 13:21:13 +00:00
parent 8344f41b9b
commit 704a56b63d

View File

@ -12,16 +12,22 @@
/* Already C11 */
#else
#ifndef __has_extension
#define __has_extension(x) 0
#endif
/*
* C11 static_assert() macro
* assert.h only defines that name for C11 and above
*/
#ifndef static_assert
#ifdef __clang__
#if defined(__clang__) && __has_extension(c_static_assert)
#define static_assert _Static_assert
#elif defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || (__GNUC__ > 4))
#warning
#define static_assert _Static_assert
#else
#define static_assert(...) ((void)0)
#define static_assert(cond, mesg) struct _C11_COMPAT_H_static_assert_unused
#endif
#endif