From: Laszlo Ersek <lersek@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] build: disable -Wmissing-braces on older compilers
Date: Fri, 20 Oct 2017 17:32:59 +0200 [thread overview]
Message-ID: <f0573dbb-c81e-c3c3-b0a6-8bafc9d0b2ac@redhat.com> (raw)
In-Reply-To: <d7f4739b-0318-ef87-67a9-73a9c5e836c0@redhat.com>
On 10/20/17 17:09, Paolo Bonzini wrote:
> On 20/10/2017 17:08, Laszlo Ersek wrote:
>> On 10/20/17 13:02, Paolo Bonzini wrote:
>>> On 20/10/2017 12:48, Peter Maydell wrote:
>>>> On 20 October 2017 at 11:12, Paolo Bonzini <pbonzini@redhat.com>
>>>> wrote:
>>>>> GCC 4.9 and newer stopped warning for missing braces around the
>>>>> "universal" C zero initializer {0}. One such initializer sneaked
>>>>> into scsi/qemu-pr-helper.c and is breaking the build with such
>>>>> older GCC versions.
>>>>>
>>>>> Detect the lack of support for the idiom, and disable the warning
>>>>> in that case.
>>>>>
>>>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>>>>
>>>> AFAIK "{}" will work and not be warned about anywhere (we
>>>> use it extensively already) so you don't need to fall back to
>>>> memset...
>>>
>>> Doh, of course that will work in scsi/qemu-pr-helper.c. In general
>>> you can use {0} but not {} to initialize a scalar, like
>>>
>>> IDontKnowIfItsAnArrayOrPointer x = {}; //might fail
>>> IDontKnowIfItsAnArrayOrPointer x = {0}; //always works
>>>
>>> I'm not sure if that matters.
>>
>> My remark below might matter even less, but:
>>
>> I'd find it regrettable if we suppressed a wrong gcc warning about a
>> valid C construct by replacing the construct with a GNU-ism that is
>> *not* standard C. :/
>
> Is {} to initialize structs a GNUism?
It is;
> struct {
> int a, b;
> } x = {};
$ gcc -fsyntax-only -std=c99 -pedantic -Wall -Wextra x.c
> x.c:3:7: warning: ISO C forbids empty initializer braces [-Wpedantic]
> } x = {};
> ^
> x.c:3:1: warning: missing initializer for field 'a' of 'struct <anonymous>' [-Wmissing-field-initializers]
> } x = {};
> ^
> x.c:2:7: note: 'a' declared here
> int a, b;
> ^
If you replace "{}" with "{ 0 }", the same command line stays quiet.
(I used: gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16).)
> (Initializing a scalar with {} is a hard error with GCC).
Thanks,
Laszlo
next prev parent reply other threads:[~2017-10-20 15:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-20 10:12 [Qemu-devel] [PATCH] build: disable -Wmissing-braces on older compilers Paolo Bonzini
2017-10-20 10:27 ` Laszlo Ersek
2017-10-20 10:37 ` Paolo Bonzini
2017-10-20 10:45 ` Laszlo Ersek
2017-10-20 10:48 ` Peter Maydell
2017-10-20 11:02 ` Paolo Bonzini
2017-10-20 15:08 ` Laszlo Ersek
2017-10-20 15:09 ` Paolo Bonzini
2017-10-20 15:32 ` Laszlo Ersek [this message]
2017-10-20 15:44 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f0573dbb-c81e-c3c3-b0a6-8bafc9d0b2ac@redhat.com \
--to=lersek@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).