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@xxxxxxxxx> 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@xxxxxxxxx> > > --- > > 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