diff options
author | Max Reitz <mreitz@redhat.com> | 2018-02-24 16:40:27 +0100 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2018-03-19 10:00:14 -0500 |
commit | 9139b5672360aaa263da1d96cdfdbe16accb6e3b (patch) | |
tree | 340addbff2f0fbb8172f5e62844d4e7d2594ab92 /include/qemu/compiler.h | |
parent | 7d0f982bfbb92fbfc1bf6c9bcaffe745996a763c (diff) | |
download | qemu-9139b5672360aaa263da1d96cdfdbe16accb6e3b.zip qemu-9139b5672360aaa263da1d96cdfdbe16accb6e3b.tar.gz qemu-9139b5672360aaa263da1d96cdfdbe16accb6e3b.tar.bz2 |
compiler: Add QEMU_BUILD_BUG_MSG() macro
_Static_assert() allows us to specify messages, and that may come in
handy. Even without _Static_assert(), encouraging developers to put a
helpful message next to the QEMU_BUILD_BUG_* may make debugging easier
whenever it breaks.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20180224154033.29559-2-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'include/qemu/compiler.h')
-rw-r--r-- | include/qemu/compiler.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 2cbe6a4..9f76269 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -82,15 +82,21 @@ int:(x) ? -1 : 1; \ } +/* QEMU_BUILD_BUG_MSG() emits the message given if _Static_assert is + * supported; otherwise, it will be omitted from the compiler error + * message (but as it remains present in the source code, it can still + * be useful when debugging). */ #if defined(CONFIG_STATIC_ASSERT) -#define QEMU_BUILD_BUG_ON(x) _Static_assert(!(x), "not expecting: " #x) +#define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg) #elif defined(__COUNTER__) -#define QEMU_BUILD_BUG_ON(x) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \ +#define QEMU_BUILD_BUG_MSG(x, msg) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \ glue(qemu_build_bug_on__, __COUNTER__) __attribute__((unused)) #else -#define QEMU_BUILD_BUG_ON(x) +#define QEMU_BUILD_BUG_MSG(x, msg) #endif +#define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x) + #define QEMU_BUILD_BUG_ON_ZERO(x) (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \ sizeof(QEMU_BUILD_BUG_ON_STRUCT(x))) |