nasm_build_assert(): use better fallback implementation

http://www.drdobbs.com/compile-time-assertions/184401873 describes a
number of possible implementations of static_assert() on compilers
that do not support it natively.  Use their best recommendation.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2017-01-24 12:24:03 -08:00
parent fc427c6fab
commit 4eb7a1f089

View File

@ -173,7 +173,7 @@ no_return nasm_assert_failed(const char *, int, const char *);
} while (0)
/*
* NASM failure at build time if x != 0
* NASM failure at build time if the argument is false
*/
#ifdef static_assert
# define nasm_build_assert(x) static_assert(x, #x)
@ -185,7 +185,9 @@ no_return nasm_assert_failed(const char *, int, const char *);
_nasm_static_fail(); \
}
#else
# define nasm_build_assert(x) (void)(sizeof(char[1-2*!(x)]))
/* See http://www.drdobbs.com/compile-time-assertions/184401873 */
# define nasm_build_assert(x) \
do { enum { _static_assert_failed = 1/(!!(x)) }; } while (0)
#endif
/*