[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <152261535982.30503.18110930471409401085.stgit@warthog.procyon.org.uk>
Date: Sun, 01 Apr 2018 21:42:39 +0100
From: David Howells <dhowells@...hat.com>
To: linux-kernel@...r.kernel.org
Subject: [PATCH 24/45] C++: Fix BUILD_BUG_ON_ZERO()
Fix BUILD_BUG_ON_ZERO() to work in C++. The construction format:
(struct { ... })
is something C++ doesn't like.
Signed-off-by: David Howells <dhowells@...hat.com>
---
include/linux/build_bug.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h
index 43d1fd50d433..7445385cd26f 100644
--- a/include/linux/build_bug.h
+++ b/include/linux/build_bug.h
@@ -20,13 +20,16 @@
#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0))
+extern int __build_bug_on_zero(void)
+ __compiletime_error("Build bug on zero");
+
/*
* Force a compilation error if condition is true, but also produce a
* result (of value 0 and type size_t), so the expression can be used
* e.g. in a structure initializer (or where-ever else comma expressions
* aren't permitted).
*/
-#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))
+#define BUILD_BUG_ON_ZERO(e) ((e) ? 0 : __build_bug_on_zero())
/*
* BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the
Powered by blists - more mailing lists