Skip to content

Commit 524b72c

Browse files
rugeGerritsenkartben
authored andcommitted
toolchain: llvm: Provide working BUILD_ASSERT macro
The resulting BUILD_ASSERT macro provided by zephyr/toolchain/gcc.h is defined to be empty, making the macro useless. This commit ensures we define it to something that actually performs a validation. When not compiling for C++ or >=C11, we rely on that cdefs.h provides _Static_assert. Signed-off-by: Rubin Gerritsen <[email protected]>
1 parent d632b1c commit 524b72c

File tree

1 file changed

+20
-0
lines changed
  • include/zephyr/toolchain

1 file changed

+20
-0
lines changed

include/zephyr/toolchain/llvm.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@
3232

3333
#include <zephyr/toolchain/gcc.h>
3434

35+
/* clear out common version. The build assert assert from gcc.h is defined to be empty */
36+
#undef BUILD_ASSERT
37+
38+
#if defined(__cplusplus) && (__cplusplus >= 201103L)
39+
40+
/* C++11 has static_assert built in */
41+
#define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG)
42+
43+
#elif !defined(__cplusplus) && ((__STDC_VERSION__) >= 201100)
44+
45+
/* C11 has static_assert built in */
46+
#define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
47+
48+
#else
49+
50+
/* Rely on that the C-library provides a static assertion function */
51+
#define BUILD_ASSERT(EXPR, MSG...) _Static_assert((EXPR), "" MSG)
52+
53+
#endif
54+
3555
#define TOOLCHAIN_WARNING_SIZEOF_ARRAY_DECAY "-Wsizeof-array-decay"
3656
#define TOOLCHAIN_WARNING_UNNEEDED_INTERNAL_DECLARATION "-Wunneeded-internal-declaration"
3757

0 commit comments

Comments
 (0)