diff --git a/configure b/configure index ff2c81f2c7..7c020c076b 100755 --- a/configure +++ b/configure @@ -4852,6 +4852,20 @@ EOF fi fi +########################################## +# check for _Static_assert() + +have_static_assert=no +cat > $TMPC << EOF +_Static_assert(1, "success"); +int main(void) { + return 0; +} +EOF +if compile_prog "" "" ; then + have_static_assert=yes +fi + ########################################## # End of CC checks # After here, no more $cc or $ld runs @@ -5848,6 +5862,10 @@ if test "$have_sysmacros" = "yes" ; then echo "CONFIG_SYSMACROS=y" >> $config_host_mak fi +if test "$have_static_assert" = "yes" ; then + echo "CONFIG_STATIC_ASSERT=y" >> $config_host_mak +fi + # Hold two types of flag: # CONFIG_THREAD_SETNAME_BYTHREAD - we've got a way of setting the name on # a thread we have a handle to diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 18e610083a..340e5fdc09 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -82,7 +82,9 @@ int:(x) ? -1 : 1; \ } -#ifdef __COUNTER__ +#if defined(CONFIG_STATIC_ASSERT) +#define QEMU_BUILD_BUG_ON(x) _Static_assert(!(x), "not expecting: " #x) +#elif defined(__COUNTER__) #define QEMU_BUILD_BUG_ON(x) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \ glue(qemu_build_bug_on__, __COUNTER__) __attribute__((unused)) #else