diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2014-09-18 18:46:21 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-09-18 18:46:21 -0400 |
commit | 15f72fb47214133818a9b20ad4d4cb3d8c4fa508 (patch) | |
tree | 07ca3c178e549b9679a75d8ab8abb28aa4a5dc2f /src/shared/macro.h | |
parent | 1e446d862a89ba3475a9df516a9e57a590e9fcd8 (diff) |
src/shared: import upstream code needed for recent commits
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/macro.h')
-rw-r--r-- | src/shared/macro.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h index e8c564837b..cea13182ec 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -37,6 +37,10 @@ #define _public_ __attribute__ ((visibility("default"))) #define _cleanup_(x) __attribute__((cleanup(x))) +/* Temporarily disable some warnings */ +#define DISABLE_WARNING_DECLARATION_AFTER_STATEMENT \ + _Pragma("GCC diagnostic push"); \ + _Pragma("GCC diagnostic ignored \"-Wdeclaration-after-statement\"") #define DISABLE_WARNING_FORMAT_NONLITERAL \ _Pragma("GCC diagnostic push"); \ @@ -103,6 +107,23 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { log_assert_failed_unreachable(t, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ } while (false) +#if defined(static_assert) +/* static_assert() is sometimes defined in a way that trips up + * -Wdeclaration-after-statement, hence let's temporarily turn off + * this warning around it. */ +#define assert_cc(expr) \ + DISABLE_WARNING_DECLARATION_AFTER_STATEMENT; \ + static_assert(expr, #expr); \ + REENABLE_WARNING +#else +#define assert_cc(expr) \ + DISABLE_WARNING_DECLARATION_AFTER_STATEMENT; \ + struct CONCATENATE(_assert_struct_, __LINE__) { \ + char x[(expr) ? 0 : -1]; \ + }; \ + REENABLE_WARNING +#endif + #define PTR_TO_INT(p) ((int) ((intptr_t) (p))) #define INT_TO_PTR(u) ((void *) ((intptr_t) (u))) #define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p))) |