Bug 63480 - -Wmissing-field-initializers should not warn about intentionally empty initializers (or that should be a separate option)
Summary: -Wmissing-field-initializers should not warn about intentionally empty initia...
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 5.0
Assignee: Marek Polacek
Keywords: diagnostic
Depends on:
Reported: 2014-10-08 04:30 UTC by Josh Triplett
Modified: 2020-08-20 16:38 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2014-10-08 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Josh Triplett 2014-10-08 04:30:59 UTC
-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?
Comment 1 Manuel López-Ibáñez 2014-10-08 09:09:14 UTC
Wasn't this fixed for C++ recently? Perhaps the code could be shared... In any case, they should behave similarly.
Comment 2 Marek Polacek 2014-10-08 09:09:43 UTC
I think it makes sense just not to warn on { }, much as we intentionally don't warn for { 0 }.
I'm testing a patch.
Comment 3 Marek Polacek 2014-10-08 09:11:40 UTC
In C++ we don't warn for { }.  OTOH, C++ warns for { 0 } - I think it should not.
Comment 4 Manuel López-Ibáñez 2014-10-08 09:28:05 UTC
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.
Comment 5 Manuel López-Ibáñez 2014-10-08 09:38:21 UTC
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.
Comment 6 Marek Polacek 2014-10-08 10:13:38 UTC
Also note PR39589, a request for -Wmissing-field-initializers=2, but it's not as trivial as it seems.
Comment 7 Marek Polacek 2014-10-09 08:26:23 UTC
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
	PR c/63480
	* c-typeck.c (pop_init_level): Don't warn about initializing
	with { }.

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

Comment 8 Marek Polacek 2014-10-09 08:27:10 UTC