[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] QEMU_BUILD_BUG_ON: use __COUNTER__

From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH] QEMU_BUILD_BUG_ON: use __COUNTER__
Date: Tue, 31 Jan 2017 10:37:12 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0

On 01/31/2017 10:07 AM, Markus Armbruster wrote:
>> I tried that first thing.
>> This generates lots of warnings if you have multiple users
>> within a function: gcc is unhappy about the redundant extern
>> declarations.
> #define QEMU_BUILD_BUG_ON(x) \
>     _Pragma("GCC diagnostic push") \
>     _Pragma("GCC diagnostic ignored \"-Wredundant-decls\"") \
>     extern char qemu_build_bug_on_[QEMU_BUILD_BUG_ON_ZERO((x))] 
> __attribute__((unused)); \
>     _Pragma("GCC diagnostic pop")

Do we know if pragma GCC diagnostic push is supported in our minimum
compiler requirements (gcc 4.1, and presumably clang just ignores the

> Drawback: natural use like
> expands into a declaration followed by an extra semicolon.

Can you emit a mid-declaration _Pragma, as in:

extern char ...[...] \
_Pragma("GCC diagnostic pop") \

Also, I guess this points out that we are inconsistent on whether we use
the __-decorated variants of all __attribute__ arguments; system headers
should always do it, since __unused__ is reserved to the implementation
but the user is free to #define unused and mess up the parse of the
header; but we aren't a system header and it obviously hasn't tripped us
up yet.

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]