Skip to content

Commit 05169a0

Browse files
lpereiraAnas Nashif
authored andcommitted
toolchain: common: Allow multiple uses of BUILD_ASSERT() in same scope
BUILD_ASSERT() was always defining a type with the name __build_assert_failure, causing issues if more than one assertion were used in the same scope. Also, use an enum instead of a typedef to avoid (possibly spurious) warnings such as these: variably modified ‘__build_assert_failure1’ at file scope [-Werror] Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
1 parent 666274f commit 05169a0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

include/toolchain/common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@
120120

121121
#ifndef BUILD_ASSERT
122122
/* compile-time assertion that makes the build fail */
123-
#define BUILD_ASSERT(EXPR) typedef char __build_assert_failure[(EXPR) ? 1 : -1]
123+
#define BUILD_ASSERT(EXPR) \
124+
enum _CONCAT(__build_assert_enum, __COUNTER__) { \
125+
_CONCAT(__build_assert, __COUNTER__) = 1 / !!(EXPR) \
126+
}
124127
#endif
125128
#ifndef BUILD_ASSERT_MSG
126129
/* build assertion with message -- common implementation swallows message. */

0 commit comments

Comments
 (0)