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

Re: [PATCH] unpack-objects: fix compilation warning/error due to missing braces

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 12, 2022, 06:28 UTC
Message-ID
<CAPig+cQMJcUc4gpRDpR=Q8M44rTjUA7SWgXNmzrnDH7V12z0dQ@mail.gmail.com>
In-Reply-To
<xmqq7d4kp8l6.fsf@gitster.g>
On Mon, Jul 11, 2022 at 12:38 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 21 quoted lines
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > On Sun, Jul 10, 2022 at 10:00 PM Han Xin <chiyutianyi@gmail.com> wrote:
> >> On Sun, Jul 10, 2022 at 4:12 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> >> > [1]: `cc --version` => "Apple LLVM version 10.0.0 (clang-1000.10.44.4)"
> >> > -       git_zstream zstream = { 0 };
> >> > +       git_zstream zstream = {{ 0 }};
> >>
> >> Not a comment, just wondering, when should I use "{ { 0 } }" and when
> >> should I use "{ 0 }"?
> >
> > I don't have a good answer. More modern `clang` versions don't seem to
> > complain about plain old `{0}` here, but the older `clang` with which
> > I'm stuck does complain.
>
> I think, from the language-lawyer perspective, "{ 0 }" is how we
> should spell these initialization when we are not using designated
> initializers, even when the first member of the struct happens to be
> a struct.
>
> The older clang that complains at you is simply buggy, and I think
> we had the same issue with older sparse.

I can't tell from your response whether or not you intend to pick up this patch. I don't disagree that older clang may be considered buggy in this regard, but older clang versions still exist in the wild, and we already support them by applying `{{0}}` when appropriate:

    % git grep -n '{ *{ *0 *} *}'
    builtin/merge-file.c:31: xmparam_t xmp = {{0}};
    builtin/worktree.c:262: struct config_set cs = { { 0 } };
    oidset.h:25:#define OIDSET_INIT { { 0 } }
    worktree.c:840: struct config_set cs = { { 0 } };

so the change made by this patch is in line with existing practice on this project.

Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 5 of 13 in “unpack-objects: fix compilation warning/error due to missing braces”
  1. unpack-objects: fix compilation warning/error due to missing bracesEric Sunshine, Jul 10, 2022
  2. Han XinJul 11, 2022
  3. Eric SunshineJul 11, 2022
  4. Junio C HamanoJul 11, 2022
  5. Eric SunshineJul 12, 2022
  6. Ævar Arnfjörð BjarmasonJul 12, 2022
  7. Eric SunshineJul 12, 2022
  8. Jeff KingJul 12, 2022
  9. Eric SunshineJul 12, 2022
  10. Ævar Arnfjörð BjarmasonJul 12, 2022
  11. Jeff KingJul 14, 2022
  12. Ævar Arnfjörð BjarmasonJul 15, 2022
  13. Junio C HamanoJul 12, 2022

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.