Discussion:
[Bug c/63480] New: -Wmissing-field-initializers should not warn about intentionally empty initializers (or that should be a separate option)
josh at joshtriplett dot org
2014-10-08 04:30:59 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

Bug ID: 63480
Summary: -Wmissing-field-initializers should not warn about
intentionally empty initializers (or that should be a
separate option)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: josh at joshtriplett dot org

-Wmissing-field-initializers warns if a positional initializer does not
initialize all fields. However, it does so even if the initializer is {},
which is a common idiom to initialize the entire structure to zero. Please
consider not warning in that specific case. If anyone actually *wants* GCC to
warn in that case, perhaps that could go in a separate -Wempty-initializer.

Alternatively, if people *really* want -Wmissing-field-initializers to warn
about {}, could we have some other warning option that only warns about missing
field initializers with non-empty initializers?
mpolacek at gcc dot gnu.org
2014-10-08 07:27:12 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-10-08
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
manu at gcc dot gnu.org
2014-10-08 09:09:14 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
CC| |manu at gcc dot gnu.org

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Wasn't this fixed for C++ recently? Perhaps the code could be shared... In any
case, they should behave similarly.
mpolacek at gcc dot gnu.org
2014-10-08 09:09:43 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think it makes sense just not to warn on { }, much as we intentionally don't
warn for { 0 }.
I'm testing a patch.
mpolacek at gcc dot gnu.org
2014-10-08 09:11:40 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
In C++ we don't warn for { }. OTOH, C++ warns for { 0 } - I think it should
not.
manu at gcc dot gnu.org
2014-10-08 09:28:05 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Found it: PR61489

I think warning for {0} is on purpose, since one cannot tell if the struct
originally had one field and now it has two. But I don't really agree with it.
I think it is too noisy.
manu at gcc dot gnu.org
2014-10-08 09:38:21 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
The C warning is also nicer than the C++ one because it says where the field is
declared. It also only mentions one missing field per declaration, whereas the
C++ warning mentions all, which is terribly noisy and repetitive.
mpolacek at gcc dot gnu.org
2014-10-08 10:13:38 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Also note PR39589, a request for -Wmissing-field-initializers=2, but it's not
as trivial as it seems.
mpolacek at gcc dot gnu.org
2014-10-08 10:13:47 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Target Milestone|--- |5.0
mpolacek at gcc dot gnu.org
2014-10-09 08:26:23 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Oct 9 08:25:50 2014
New Revision: 216031

URL: https://gcc.gnu.org/viewcvs?rev=216031&root=gcc&view=rev
Log:
PR c/63480
* c-typeck.c (pop_init_level): Don't warn about initializing
with { }.

* gcc.dg/pr63480.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/pr63480.c
Modified:
trunk/gcc/c/ChangeLog
trunk/gcc/c/c-typeck.c
trunk/gcc/testsuite/ChangeLog
mpolacek at gcc dot gnu.org
2014-10-09 08:27:10 UTC
Permalink
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63480

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

Loading...