From 47b079afc91467a64937c24590bc6c9acb579f13 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 22 Aug 2018 00:32:30 -0400 Subject: [PATCH] Debug.h: Implement a real STATIC_ASSERT on non-GCC2. --- headers/os/support/Debug.h | 22 ++++++++++++++-------- headers/private/kernel/debug.h | 18 ++++++++++++------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/headers/os/support/Debug.h b/headers/os/support/Debug.h index 9cc39fd8c9..cc701cab73 100644 --- a/headers/os/support/Debug.h +++ b/headers/os/support/Debug.h @@ -63,7 +63,7 @@ extern "C" { #define ASSERT_WITH_MESSAGE(expr, msg) \ (!(expr) ? _debuggerAssert( __FILE__,__LINE__, msg) \ - : (int)0) + : (int)0) #define TRESPASS() DEBUGGER("Should not be here"); @@ -72,7 +72,7 @@ extern "C" { #else /* DEBUG == 0 */ #define SET_DEBUG_ENABLED(FLAG) (void)0 #define IS_DEBUG_ENABLED() (void)0 - + #define SERIAL_PRINT(ARGS) (void)0 #define PRINT(ARGS) (void)0 #define PRINT_OBJECT(OBJ) (void)0 @@ -90,12 +90,18 @@ extern "C" { /* STATIC_ASSERT is a compile-time check that can be used to */ /* verify static expressions such as: STATIC_ASSERT(sizeof(int64) == 8); */ -#define STATIC_ASSERT(x) \ - do { \ - struct __staticAssertStruct__ { \ - char __static_assert_failed__[2*(x) - 1]; \ - }; \ - } while (false) +#if __GNUC__ >= 5 && !defined(__cplusplus) +# define STATIC_ASSERT(x) _Static_assert(x, "static assert failed!") +#elif defined(__cplusplus) && __cplusplus >= 201103L +# define STATIC_ASSERT(x) static_assert(x, "static assert failed!") +#else +# define STATIC_ASSERT(x) \ + do { \ + struct __staticAssertStruct__ { \ + char __static_assert_failed__[2*(x) - 1]; \ + }; \ + } while (false) +#endif #endif /* _DEBUG_H */ diff --git a/headers/private/kernel/debug.h b/headers/private/kernel/debug.h index 45332e4dbd..c8037ca8ee 100644 --- a/headers/private/kernel/debug.h +++ b/headers/private/kernel/debug.h @@ -69,12 +69,18 @@ # define ASSERT_PRINT(x, format, args...) do { } while(0) #endif -#define STATIC_ASSERT(x) \ - do { \ - struct __staticAssertStruct__ { \ - char __static_assert_failed__[2*(x) - 1]; \ - }; \ - } while (false) +#if __GNUC__ >= 5 && !defined(__cplusplus) +# define STATIC_ASSERT(x) _Static_assert(x, "static assert failed!") +#elif defined(__cplusplus) && __cplusplus >= 201103L +# define STATIC_ASSERT(x) static_assert(x, "static assert failed!") +#else +# define STATIC_ASSERT(x) \ + do { \ + struct __staticAssertStruct__ { \ + char __static_assert_failed__[2*(x) - 1]; \ + }; \ + } while (false) +#endif #if KDEBUG # define KDEBUG_ONLY(x) x