diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-14 14:21:16 -0800 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-14 15:42:03 -0800 |
commit | b7f24e7715d8fdca52fda7fb9df1b70d8d4bbc6b (patch) | |
tree | 15669a93ec7bc21743b0928d04b7861180082cb6 /include/compiler.h | |
parent | c3c6cea83804e7ba36b31d15ba25954ea3a5bdfd (diff) | |
download | nasm-b7f24e7715d8fdca52fda7fb9df1b70d8d4bbc6b.tar.gz |
nasm_assert(): try to run at compile time if possible
Try to make nasm_assert() do a static assert if the argument can be
evaluated at compile time by any particular compiler. We also provide
nasm_try_static_assert() which will assert a compile-time expression
if and only if we can determine we have a constant at compile time
*and* we know that the compiler has a way to handle it.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'include/compiler.h')
-rw-r--r-- | include/compiler.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/compiler.h b/include/compiler.h index 7beeb8fe..f0258a8b 100644 --- a/include/compiler.h +++ b/include/compiler.h @@ -359,6 +359,27 @@ size_t strnlen(const char *s, size_t maxlen); #endif /* + * If we can guarantee that a particular expression is constant, use it, + * otherwise use a different version. + */ +#if defined(__GNUC__) && (__GNUC__ >= 3) +# define not_pedantic_start \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wpedantic\"") +# define not_pedantic_end \ + _Pragma("GCC diagnostic pop") +#else +# define not_pedantic_start +# define not_pedantic_end +#endif + +#ifdef HAVE___BUILTIN_CHOOSE_EXPR +# define if_constant(x,y) __builtin_choose_expr(is_constant(x),(x),(y)) +#else +# define if_constant(x,y) (y) +#endif + +/* * The autoconf documentation states: * * `va_copy' |