[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 05/36] compiler: Add QEMU_BUILD_BUG_MSG() macro
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PULL 05/36] compiler: Add QEMU_BUILD_BUG_MSG() macro |
Date: |
Mon, 12 Mar 2018 13:35:56 -0500 |
From: Max Reitz <address@hidden>
_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 <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Alberto Garcia <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
---
include/qemu/compiler.h | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 2cbe6a4f16e..9f762695d11 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)))
--
2.14.3
- [Qemu-devel] [PULL 00/36] QAPI patches for 2018-03-12, 2.12 softfreeze, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 02/36] qlit: use QType instead of int, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 05/36] compiler: Add QEMU_BUILD_BUG_MSG() macro,
Eric Blake <=
- [Qemu-devel] [PULL 08/36] qapi: Remove qobject_to_X() functions, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 06/36] qapi: Add qobject_to(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 03/36] qlit: add qobject_from_qlit(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 09/36] qapi: Make more of qobject_to(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 04/36] qapi: generate a literal qobject for introspection, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 16/36] monitor: move skip_flush into monitor_data_init, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 18/36] monitor: unify global init, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 11/36] block: Deprecate "backing": "", Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 17/36] monitor: move the cur_mon hack deeper for QMP, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 10/36] block: Handle null backing link, Eric Blake, 2018/03/12