lkml.org 
[lkml]   [2018]   [Apr]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 24/45] C++: Fix BUILD_BUG_ON_ZERO()
From
Date
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@redhat.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
\
 
 \ /
  Last update: 2018-04-01 22:47    [W:0.095 / U:6.580 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site