Re: [PATCH] Fixes compile warning with -Wimplicit-fallthrough CFLAGS
- From
Jeff King <peff@peff.net>
- Date
- Jan 23, 2018, 18:37 UTC
- Message-ID
- <20180123183731.GA18333@sigill.intra.peff.net>
- In-Reply-To
- <xmqqd120ifvu.fsf@gitster.mtv.corp.google.com>
On Tue, Jan 23, 2018 at 10:33:57AM -0800, Junio C Hamano wrote:
Show 19 quoted lines
> Jeff King <peff@peff.net> writes:
>
> >> diff --git a/apply.c b/apply.c
> >> index 321a9fa68..a22fb2881 100644
> >> --- a/apply.c
> >> +++ b/apply.c
> >> @@ -1450,7 +1450,7 @@ static void recount_diff(const char *line, int size, struct fragment *fragment)
> >> switch (*line) {
> >> case ' ': case '\n':
> >> newlines++;
> >> - /* fall through */
> >> + GIT_FALLTHROUGH;
> >
> > Ugh, the semi-colon there makes it look like it's actual code. If we go
> > this route, I wonder if it's worth hiding it inside the macro.
>
> What? You mean to shout in all caps without even terminating the
> line with any punctuation? Please don't---I am sure it will break
> auto indentation people rely on from their editors.True, that may be even worse. I just wonder if we can do something to make it look more obviously like a non-code attribute. The actual syntax is something like:
[[fallthrough]];
which is pretty horrid, but at least a bit easier to see. gcc also provides "__attribute__((fallthrough))", but I don't think it works with clang.
I vastly prefer the comment approach if we can use it. Apparently clang doesn't support it, but I have also not managed to get clang (either version 4, 6, or the upcoming 7) to actually report anything via -Wimplicit-fallthrough, either. Maybe I'm holding it wrong.
-Peff