nasmlib.h: slightly tidy up the definition of nasm_build_assert()

"Assertion failed" is likely to be redundant with static_assert().

__attribute__((error)) is only guaranteed to work while optimizing, so
do not use it unless __OPTIMIZE__ is defined.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2017-01-22 21:06:05 -08:00
parent cd0c7ddc40
commit fc427c6fab

View File

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- * /* ----------------------------------------------------------------------- *
* *
* Copyright 1996-2016 The NASM Authors - All Rights Reserved * Copyright 1996-2017 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for * See the file AUTHORS included with the NASM distribution for
* the specific copyright holders. * the specific copyright holders.
* *
@ -176,13 +176,13 @@ no_return nasm_assert_failed(const char *, int, const char *);
* NASM failure at build time if x != 0 * NASM failure at build time if x != 0
*/ */
#ifdef static_assert #ifdef static_assert
# define nasm_build_assert(x) static_assert(x, "assertion " #x " failed") # define nasm_build_assert(x) static_assert(x, #x)
#elif defined(HAVE_FUNC_ATTRIBUTE_ERROR) #elif defined(HAVE_FUNC_ATTRIBUTE_ERROR) && defined(__OPTIMIZE__)
# define nasm_build_assert(x) \ # define nasm_build_assert(x) \
if (!(x)) { \ if (!(x)) { \
extern void __attribute__((error("assertion " #x " failed"))) \ extern void __attribute__((error("assertion " #x " failed"))) \
fail(void); \ _nasm_static_fail(void); \
fail(); \ _nasm_static_fail(); \
} }
#else #else
# define nasm_build_assert(x) (void)(sizeof(char[1-2*!(x)])) # define nasm_build_assert(x) (void)(sizeof(char[1-2*!(x)]))