Re: [PATCH] unpack-objects: fix compilation warning/error due to missing braces
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jul 11, 2022, 02:41 UTC
- Message-ID
- <CAPig+cQJWgerk08j=1b=aWRZsKBu3BnEACQuiqktU4BwzM-xaA@mail.gmail.com>
- In-Reply-To
- <CAO0brD0PBXDqe2HDdjg1ZhXWoYZihQ0=SY80UR+Cy3xRqqH8Sg@mail.gmail.com>
On Sun, Jul 10, 2022 at 10:00 PM Han Xin <chiyutianyi@gmail.com> wrote:
Show 19 quoted lines
> On Sun, Jul 10, 2022 at 4:12 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > On macOS High Sierra (10.13), Apple's `clang`[1] complains about missing
> > braces around initialization of a subobject, which is problematic when
> > building with `DEVELOPER=YesPlease` which enables `-Werror`:
> >
> > builtin/unpack-objects.c:388:26: error: suggest braces around
> > initialization of subobject [-Werror,-Wmissing-braces]
> > git_zstream zstream = { 0 };
> >
> > [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 didn't get the error with "Apple clang version 13.0.0
> (clang-1300.0.29.30)", because it's
> a higher version ?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. Aside from actually building the project with an older `clang` (or older Apple-specific `clang`), it may be sufficient to inspect the structure that's being initialized to see if the first element is itself a subobject. However, I'm not sure it's worth the effort to do so considering how rare this problem seems to be.