git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Elia Pinto <gitter.spiros@gmail.com>, Git List <git@vger.kernel.org>
Subject: Re: [PATCH] Fixes compile warning with -Wimplicit-fallthrough CFLAGS
Date: Mon, 22 Jan 2018 19:59:50 -0500	[thread overview]
Message-ID: <20180123005950.GH26357@sigill.intra.peff.net> (raw)
In-Reply-To: <CAPig+cSuBRcM7BBw1MKOOVSZv+CVVrY-dWfSGj+31DA4QMrruA@mail.gmail.com>

On Mon, Jan 22, 2018 at 07:54:18PM -0500, Eric Sunshine wrote:

> On Mon, Jan 22, 2018 at 6:51 PM, Elia Pinto <gitter.spiros@gmail.com> wrote:
> > This patch add explicit fallthrough compiler attribute
> > when needed on switch case statement eliminating
> > the compile warning [-Werror=implicit-fallthrough=].
> > It does this by means of a macro that takes into account
> > the versions of the compilers that include that attribute.
> > [...]
> > Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
> > ---
> > diff --git a/convert.c b/convert.c
> > @@ -1554,7 +1554,7 @@ static int ident_filter_fn(struct stream_filter *filter,
> >                 switch (ident->state) {
> >                 default:
> >                         strbuf_add(&ident->left, head, ident->state);
> > -                       /* fallthrough */
> > +                       GIT_FALLTHROUGH;
> >                 case IDENT_SKIPPING:
> >                         /* fallthrough */
> 
> Why doesn't this /* fallthrough */ deserve the same treatment?
> 
> >                 case IDENT_DRAINING:

I can't answer that philosophically, but I can tell you why the compiler
does not complain. :)

Usually case arms with no statements between them are exempt from
fallthrough warnings. So:

  switch (foo)
  case 1:
  case 2:
  case 3:
     /* do one thing */
     break;
  case 4:
     /* do another thing */
     break;
  }

does not need any annotations for cases 1 and 2 to fallthrough. Which
means that the original comment was not actually necessary for the
compiler, though the original author considered it a useful comment.

So there you get into philosophy. Should it be converted to a
compiler-visible annotation, or is it better left as a comment?

-Peff

  reply	other threads:[~2018-01-23  0:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-22 23:51 [PATCH] Fixes compile warning with -Wimplicit-fallthrough CFLAGS Elia Pinto
2018-01-23  0:07 ` Jeff King
2018-01-23 18:33   ` Junio C Hamano
2018-01-23 18:37     ` Jeff King
2018-01-23  0:54 ` Eric Sunshine
2018-01-23  0:59   ` Jeff King [this message]
2018-01-23  6:31     ` Jacob Keller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180123005950.GH26357@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitter.spiros@gmail.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).