From 55b5d88b01ef9e1101df62ee49b3f34e58877faa Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 18 Jan 2023 05:26:41 +0100 Subject: [PATCH] unix,win: use static_assert when available (#3189) Fixes: https://github.com/libuv/libuv/issues/3131 --- src/uv-common.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/uv-common.h b/src/uv-common.h index 6c537e9e..26d0e49b 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -53,8 +53,13 @@ extern int snprintf(char*, size_t, const char*, ...); #define container_of(ptr, type, member) \ ((type *) ((char *) (ptr) - offsetof(type, member))) +/* C11 defines static_assert to be a macro which calls _Static_assert. */ +#if defined(static_assert) +#define STATIC_ASSERT(expr) static_assert(expr, #expr) +#else #define STATIC_ASSERT(expr) \ void uv__static_assert(int static_assert_failed[1 - 2 * !(expr)]) +#endif #if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 7) #define uv__load_relaxed(p) __atomic_load_n(p, __ATOMIC_RELAXED)