mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-01-18 16:25:05 +08:00
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:
parent
cd0c7ddc40
commit
fc427c6fab
@ -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
|
||||
* 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
|
||||
*/
|
||||
#ifdef static_assert
|
||||
# define nasm_build_assert(x) static_assert(x, "assertion " #x " failed")
|
||||
#elif defined(HAVE_FUNC_ATTRIBUTE_ERROR)
|
||||
# define nasm_build_assert(x) static_assert(x, #x)
|
||||
#elif defined(HAVE_FUNC_ATTRIBUTE_ERROR) && defined(__OPTIMIZE__)
|
||||
# define nasm_build_assert(x) \
|
||||
if (!(x)) { \
|
||||
extern void __attribute__((error("assertion " #x " failed"))) \
|
||||
fail(void); \
|
||||
fail(); \
|
||||
_nasm_static_fail(void); \
|
||||
_nasm_static_fail(); \
|
||||
}
|
||||
#else
|
||||
# define nasm_build_assert(x) (void)(sizeof(char[1-2*!(x)]))
|
||||
|
Loading…
Reference in New Issue
Block a user