Skip to content
  • Jeff King's avatar
    consistently use "fallthrough" comments in switches · 1cf01a34
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Gcc 7 adds -Wimplicit-fallthrough, which can warn when a
    switch case falls through to the next case. The general idea
    is that the compiler can't tell if this was intentional or
    not, so you should annotate any intentional fall-throughs as
    such, leaving it to complain about any unannotated ones.
    
    There's a GNU __attribute__ which can be used for
    annotation, but of course we'd have to #ifdef it away on
    non-gcc compilers. Gcc will also recognize
    specially-formatted comments, which matches our current
    practice. Let's extend that practice to all of the
    unannotated sites (which I did look over and verify that
    they were behaving as intended).
    
    Ideally in each case we'd actually give some reasons in the
    comment about why we're falling through, or what we're
    falling through to. And gcc does support that with
    -Wimplicit-fallthrough=2, which relaxes the comment pattern
    matching to anything that contains "fallthrough" (or a
    variety of spelling variants). However, this isn't the
    default for -Wimplicit-fallthrough, nor for -Wextra. In the
    name of simplicity, it's probably better for us to support
    the default level, which requires "fallthrough" to be the
    only thing in the comment (modulo some window dressing like
    "else" and some punctuation; see the gcc manual for the
    complete set of patterns).
    
    This patch suppresses all warnings due to
    -Wimplicit-fallthrough. We might eventually want to add that
    to the DEVELOPER Makefile knob, but we should probably wait
    until gcc 7 is more widely adopted (since earlier versions
    will complain about the unknown warning type).
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    1cf01a34