git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 00/52] fix some -Wmissing-field-initializer warnings

From
Jeff King <peff@peff.net>
Date
May 30, 2019, 12:04 UTC
Message-ID
<20190530120441.GD31607@sigill.intra.peff.net>
In-Reply-To
<0f1c5a49-f971-848d-700e-9c124ae8e617@kdbg.org>
On Thu, May 30, 2019 at 10:47:37AM +0200, Johannes Sixt wrote:
Show 17 quoted lines
> I had a brief look at the series. IMO, it is a mistake to appease
> -Wmissing-field-initializer.
> 
> We have two sorts of initializers:
> 
>  - zero initializers: they just want to null out every field,
>    like CHILD_PROCESS_INIT and ad-hoc initializers of structs
>    such as xpparam_t pp = { 0 }; in range-diff.c
> 
>  - value initializers are always macros, such as STRING_LIST_INIT_DUP
>    and the OPT_* family.
> 
> I am strongly against forcing zero initializers to write down a value
> for every field. It is much more preferable to depend on that the
> compiler does the right thing with them. -Wmissing-field-initializer
> would provide guidance in the wrong direction. A zero initializer looks
> like this: = { 0 }; and nothing else.

I had a similar impression while perusing the commits. I don't mind forcing some extra work on programmers to appease a warning if disregarding it is a common source of errors. But I didn't see any real bug-fixes in the series, so it doesn't seem like that good a tradeoff to me.

Contrast that with the -Wunused-parameters warning. I found a dozen or so actual bugs by sifting through the results, and another couple dozen spots where the code could be cleaned up or simplified. If we want to shut up the warning completely (so we can pay attention to it), we'll then have to annotate probably a couple hundred spots, and keep those annotations up to date. But I feel better doing that knowing that it's shown real-world value.

-Peff
Previous: Johannes SixtNext: Ramsay Jones
Message 5 of 6 in “fix some -Wmissing-field-initializer warnings”
  1. 00/52 fix some -Wmissing-field-initializer warningsRamsay Jones, May 24, 2019
  2. Ævar Arnfjörð BjarmasonMay 24, 2019
  3. Ramsay JonesMay 24, 2019
  4. Johannes SixtMay 30, 2019
  5. Jeff KingMay 30, 2019
  6. Ramsay JonesMay 30, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.