[systemd-devel] [PATCH] Remove static_assert related warnings

Lennart Poettering lennart at poettering.net
Thu Feb 20 09:08:31 PST 2014


On Thu, 20.02.14 14:38, Holger Schurig (holgerschurig at gmail.com) wrote:

> Make macro assert_cc() not emit "declaration after statements" warnings.
> 
> This can be done by using the GCC pragmas 'diagnostic ignore "undefined"'.
> In order to be able to use that pragma inside a macro, we need to put it
> into the (C99-introduced) _Pragma() pseudo-function.

Ah! Nice! I thought a couple of times about using #pragma for this
but always ran against the wall that #pragma cannot appear in
macros. Thanks for the pointer to _Pragma()! This is a great fix!

I have now commited a change inspired by your patch! Thanks a lot!

> ---
>  src/shared/macro.h |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/src/shared/macro.h b/src/shared/macro.h
> index dfbc201..f93a4f0 100644
> --- a/src/shared/macro.h
> +++ b/src/shared/macro.h
> @@ -156,7 +156,11 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
>  #if defined(static_assert)
>  #define assert_cc(expr) static_assert(expr, #expr)
>  #else
> -#define assert_cc(expr) struct UNIQUE(_assert_struct_) { char x[(expr) ? 0 : -1]; };
> +#define assert_cc(expr) \
> + _Pragma("GCC diagnostic push"); \
> + _Pragma("GCC diagnostic ignored \"-Wdeclaration-after-statement\""); \
> + struct UNIQUE(_assert_struct_) { char x[(expr) ? 0 : -1]; }; \
> + _Pragma("GCC diagnostic pop");
>  #endif
>  
>  #define assert_return(expr, r)                                          \


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list