X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fmacro.h;h=959a9f7fb1533cd11d918ffee7fcc1b8ea22b19f;hb=7ebe131a9f37fe5a3a15f69962d21cb7e063dff8;hp=79bee0396c3a52c4bed07f28f1878915bad8b282;hpb=919ce0b7affc6fbd68598b709faf477f56c22ac1;p=elogind.git diff --git a/src/shared/macro.h b/src/shared/macro.h index 79bee0396..959a9f7fb 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -46,6 +46,14 @@ #define _alignas_(x) __attribute__((aligned(__alignof(x)))) #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 REENABLE_WARNING \ + _Pragma("GCC diagnostic pop") + /* automake test harness */ #define EXIT_TEST_SKIP 77 @@ -117,6 +125,13 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { _a < _b ? _a : _b; \ }) +#define LESS_BY(A,B) \ + __extension__ ({ \ + typeof(A) _A = (A); \ + typeof(B) _B = (B); \ + _A > _B ? _A - _B : 0; \ + }) + #ifndef CLAMP #define CLAMP(x, low, high) \ __extension__ ({ \ @@ -147,9 +162,20 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { } while (false) #if defined(static_assert) -#define assert_cc(expr) static_assert(expr, #expr) +/* 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) struct UNIQUE(_assert_struct_) { char x[(expr) ? 0 : -1]; }; +#define assert_cc(expr) \ + DISABLE_WARNING_DECLARATION_AFTER_STATEMENT; \ + struct UNIQUE(_assert_struct_) { \ + char x[(expr) ? 0 : -1]; \ + }; \ + REENABLE_WARNING #endif #define assert_return(expr, r) \