From: Richard Sandiford <richard.sandiford@arm.com>
To: Alexey Neyman <stilor@att.net>
Cc: gcc-help@gcc.gnu.org
Subject: Re: -Wmissing-field-initializers false positive with compound literals
Date: Fri, 04 Feb 2022 08:29:20 +0000 [thread overview]
Message-ID: <mptwnibavbz.fsf@arm.com> (raw)
In-Reply-To: <d6e5a2c4-20f6-23d0-1e92-a6b0d3234220@att.net> (Alexey Neyman's message of "Thu, 3 Feb 2022 12:03:46 -0800")
Alexey Neyman <stilor@att.net> writes:
> Hi all,
>
> I've encountered a weird behavior of -Wmissing-field-initializers option
> (which is a part of -Wextra) regarding structure initializers that
> contain compound literals as initializers for some of their fields.
> Reproduced with all GCC versions from 4.8.5 to 11.2.
>
> Consider the following test case:
>
> struct foo {
> const char *a1;
> const char * const *a2;
> void *a3;
> void *a4;
> };
>
> const char *aux[] = { "y", 0 };
>
> struct foo a = {
> .a1 = "x",
> #if defined(CASE1)
> .a2 = (const char * const []){ "y", 0 },
> #elif defined(CASE2)
> .a2 = aux,
> #elif defined(CASE3)
> .a2 = 0,
> #elif defined(CASE4)
> /* .a2 not initialized */
> #elif defined(CASE5)
> .a2 = (const char * const []){ "y", 0 },
> .a3 = 0,
> #endif
> };
>
> struct foo b = {
> .a2 = (const char * const []){ "y", 0 },
> .a1 = "x",
> };
>
> CASE1 gives a warning about 'a3' field being initialized, despite the
> manual stating that named field initializers should prevent this warning
> from being generated. CASE2 initializes the field to point to an
> explicitly defined array, and it works with no warnings. CASE3 uses a
> constant as an initializer and also works without warnings. CASE5
> initializes the field 'a3' and produces no warnings about the next
> field, 'a4'.
>
> Reversing the order of the 'a1' and 'a2' initializers (as in the 'b'
> variable) also does not produce a warning. It seems that the warning is
> only produced if the last initialized field in a structure uses a
> compound literal.
>
> Looks like a bug to me; please confirm that I should file it into GCC's
> bugzilla.
Yeah, I agree it's a bug. I think it's likely to be the same underlying
issue as PR82283, so I've copied the example there (hope you don't mind).
Thanks,
Richard
prev parent reply other threads:[~2022-02-04 8:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <d6e5a2c4-20f6-23d0-1e92-a6b0d3234220.ref@att.net>
2022-02-03 20:03 ` Alexey Neyman
2022-02-04 8:29 ` Richard Sandiford [this message]
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=mptwnibavbz.fsf@arm.com \
--to=richard.sandiford@arm.com \
--cc=gcc-help@gcc.gnu.org \
--cc=stilor@att.net \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).