Messages in this thread Patch in this message | | | Date | Tue, 02 Sep 2008 19:07:29 +0300 | From | Boaz Harrosh <> | Subject | Re: [PATCH 5/5 ver3] debug: BUILD_BUG_ON: error on non-const expressions |
| |
Fix BUILD_BUG_ON to not silently drop non-compile-time visible expressions. It will now produce a compilation error if so.
The code to BUILD_BUG_ON_ZERO was done by: Jan Beulich <jbeulich@novell.com>
The code to BUILD_BUG_ON is a small variation to Jan's code inspired by Rusty Russell. Which gives me better compilations semantics, and makes BUILD_BUG_ON behave more like BUG_ON.
Signed-off-by: Boaz Harrosh <bharrosh@panasas.com> TO: Jan Beulich <jbeulich@novell.com> CC: Ingo Molnar <mingo@elte.hu> CC: Rusty Russell <rusty@rustcorp.com.au> CC: Alexey Dobriyan <adobriyan@gmail.com> CC: Andrew Morton <akpm@linux-foundation.org> CC: Theodore Tso <tytso@mit.edu> CC: David S. Miller <davem@davemloft.net> --- include/linux/compiler.h | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 90fa975..f882410 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -194,14 +194,15 @@ extern void __chk_io_ptr(const volatile void __iomem *); */ #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) -/* Force a compilation error if condition is true */ -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) - /* 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 + e.g. in a structure initializer (or where-ever full statements aren't permitted). */ -#define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1) +#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int: -!!(e); })) + +/* Force a compilation error if condition is true */ +#define BUILD_BUG_ON(e) \ + do { struct {int: -!!(e); } x __maybe_unused; } while (0) /* Trap pasters of __FUNCTION__ at compile-time */ #define __FUNCTION__ (__func__) -- 1.5.6.rc1.5.gadf6
| |