From 5e44a1008f9ae6570bc3dc5841110381ae8cc4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 13 Nov 2018 21:43:11 +0100 Subject: [PATCH 1/2] Define STATIC_ASSERT(cond, msg) to be _Static_assert(cond, msg) everywhere but on Windows where it stays to be INSIST(cond) --- lib/isc/include/isc/util.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 97eb51a193..ecd9e8c52a 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -208,6 +208,18 @@ #define ISC_UNREACHABLE() #endif +#if !defined(__has_feature) +#define __has_feature(x) 0 +#endif + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 6) +#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) +#elif __has_feature(c_static_assert) +#define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) +#else +#define STATIC_ASSERT(cond, msg) INSIST(cond) +#endif + #ifdef UNIT_TESTING extern void mock_assert(const int result, const char* const expression, const char * const file, const int line); From de6f43d071b194bdcede74f340020a3ca6e05e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 13 Nov 2018 21:44:08 +0100 Subject: [PATCH 2/2] Use static assertion to check for correct alignment size --- lib/isc/mem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 0b72e41e8d..7a2691f481 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -747,7 +747,8 @@ isc_mem_createx(size_t init_max_size, size_t target_size, REQUIRE(memalloc != NULL); REQUIRE(memfree != NULL); - INSIST((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0); + STATIC_ASSERT((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0, + "wrong alignment size"); RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);