Skip to content

Commit

Permalink
toolchain/gcc: Limit use of _Static_assert
Browse files Browse the repository at this point in the history
This C11 feature doesn't work when building C++ code, but the C++
version is based on C++11's static_assert(), which we don't have in
-std=c++98 either.

Signed-off-by: Andy Ross <andyross@google.com>
  • Loading branch information
andyross committed Mar 1, 2023
1 parent 8d585b8 commit 7359b25
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/zephyr/toolchain/gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@
#define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG)

/*
* GCC 4.6 and higher have the C11 _Static_assert built in, and its
* GCC 4.6 and higher have the C11 _Static_assert built in and its
* output is easier to understand than the common BUILD_ASSERT macros.
* Don't use this in C++98 mode though (which we can hit, as
* static_assert() is not available)
*/
#elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
(__STDC_VERSION__) >= 201100
#elif !defined(CONFIG_STD_CPP98) && \
((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
(__STDC_VERSION__) >= 201100)
#define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
#else
#define BUILD_ASSERT(EXPR, MSG...)
Expand Down

0 comments on commit 7359b25

Please sign in to comment.