From: Jim Meyering Date: Thu, 18 May 2017 15:36:27 +0000 (-0700) Subject: fallthrough: update for GCC 7/8 X-Git-Tag: v1.0~6129 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=11fdf80b21f2b40a10687b9a3d16c852b19d512c;p=gnulib.git fallthrough: update for GCC 7/8 * lib/quotearg.c (FALLTHROUGH): New macro. Use it whenever one switch case falls through into the next, replacing "/* Fall through */" comments. This exposed one instance of an unwarranted "fall through" comment: unwarranted because it preceded a "goto" label not a case statement. * lib/freopen-safer.c (freopen_safer): Likewise. * lib/fts.c (leaf_optimization_applies): Likewise. * lib/unistr/u8-uctomb-aux.c (u8_uctomb_aux): Likewise. * tests/test-getopt_long.h (getopt_long_loop): Likewise. * tests/test-tsearch.c (mangle_tree): Likewise. Also include tests/macros.h for the definition. * tests/test-argp.c (group1_parser): Likewise. * tests/test-getopt.h (getopt_loop): Likewise. --- diff --git a/ChangeLog b/ChangeLog index 46714cdd49..807c8ed854 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2017-05-18 Jim Meyering + + fallthrough: update for GCC 7/8 + * lib/quotearg.c (FALLTHROUGH): New macro. + Use it whenever one switch case falls through into the next, + replacing "/* Fall through */" comments. This exposed one + instance of an unwarranted "fall through" comment: unwarranted + because it preceded a "goto" label not a case statement. + * lib/freopen-safer.c (freopen_safer): Likewise. + * lib/fts.c (leaf_optimization_applies): Likewise. + * lib/unistr/u8-uctomb-aux.c (u8_uctomb_aux): Likewise. + * tests/test-getopt_long.h (getopt_long_loop): Likewise. + * tests/test-tsearch.c (mangle_tree): Likewise. Also include + tests/macros.h for the definition. + * tests/test-argp.c (group1_parser): Likewise. + * tests/test-getopt.h (getopt_loop): Likewise. + 2017-05-19 Paul Eggert argp: fix shift bug diff --git a/lib/freopen-safer.c b/lib/freopen-safer.c index 42dc39c7dd..be84ae68a2 100644 --- a/lib/freopen-safer.c +++ b/lib/freopen-safer.c @@ -26,6 +26,14 @@ #include #include +#ifndef FALLTHROUGH +# if __GNUC__ < 7 +# define FALLTHROUGH ((void) 0) +# else +# define FALLTHROUGH __attribute__ ((__fallthrough__)) +# endif +#endif + /* Guarantee that FD is open; all smaller FDs must already be open. Return true if successful. */ static bool @@ -69,15 +77,15 @@ freopen_safer (char const *name, char const *mode, FILE *f) default: /* -1 or not a standard stream. */ if (dup2 (STDERR_FILENO, STDERR_FILENO) != STDERR_FILENO) protect_err = true; - /* fall through */ + FALLTHROUGH; case STDERR_FILENO: if (dup2 (STDOUT_FILENO, STDOUT_FILENO) != STDOUT_FILENO) protect_out = true; - /* fall through */ + FALLTHROUGH; case STDOUT_FILENO: if (dup2 (STDIN_FILENO, STDIN_FILENO) != STDIN_FILENO) protect_in = true; - /* fall through */ + FALLTHROUGH; case STDIN_FILENO: /* Nothing left to protect. */ break; diff --git a/lib/fts.c b/lib/fts.c index fabaa97d18..3bac3244ea 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -203,6 +203,14 @@ enum Fts_stat while (false) #endif +#ifndef FALLTHROUGH +# if __GNUC__ < 7 +# define FALLTHROUGH ((void) 0) +# else +# define FALLTHROUGH __attribute__ ((__fallthrough__)) +# endif +#endif + static FTSENT *fts_alloc (FTS *, const char *, size_t) internal_function; static FTSENT *fts_build (FTS *, int) internal_function; static void fts_lfree (FTSENT *) internal_function; @@ -732,11 +740,11 @@ leaf_optimization_applies (int dir_fd) of large directories, so as per NFS should return true. However st_nlink values are not accurate on all implementations as per . */ - /* fall through */ + FALLTHROUGH; case S_MAGIC_PROC: /* Per /proc may have bogus stat.st_nlink values. */ - /* fall through */ + FALLTHROUGH; default: return false; } diff --git a/lib/quotearg.c b/lib/quotearg.c index 26903c711a..f6570330b9 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -54,6 +54,14 @@ #define INT_BITS (sizeof (int) * CHAR_BIT) +#ifndef FALLTHROUGH +# if __GNUC__ < 7 +# define FALLTHROUGH ((void) 0) +# else +# define FALLTHROUGH __attribute__ ((__fallthrough__)) +# endif +#endif + struct quoting_options { /* Basic quoting style. */ @@ -310,7 +318,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, case c_maybe_quoting_style: quoting_style = c_quoting_style; elide_outer_quotes = true; - /* Fall through. */ + FALLTHROUGH; case c_quoting_style: if (!elide_outer_quotes) STORE ('"'); @@ -365,14 +373,14 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, case shell_escape_quoting_style: backslash_escapes = true; - /* Fall through. */ + FALLTHROUGH; case shell_quoting_style: elide_outer_quotes = true; - /* Fall through. */ + FALLTHROUGH; case shell_escape_always_quoting_style: if (!elide_outer_quotes) backslash_escapes = true; - /* Fall through. */ + FALLTHROUGH; case shell_always_quoting_style: quoting_style = shell_always_quoting_style; if (!elide_outer_quotes) @@ -505,7 +513,6 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, if (quoting_style == shell_always_quoting_style && elide_outer_quotes) goto force_outer_quoting_style; - /* Fall through. */ c_escape: if (backslash_escapes) { @@ -517,14 +524,14 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, case '{': case '}': /* sometimes special if isolated */ if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1)) break; - /* Fall through. */ + FALLTHROUGH; case '#': case '~': if (i != 0) break; - /* Fall through. */ + FALLTHROUGH; case ' ': c_and_shell_quote_compat = true; - /* Fall through. */ + FALLTHROUGH; case '!': /* special in bash */ case '"': case '$': case '&': case '(': case ')': case '*': case ';': diff --git a/lib/unistr/u8-uctomb-aux.c b/lib/unistr/u8-uctomb-aux.c index b6adbe049a..72d35d814f 100644 --- a/lib/unistr/u8-uctomb-aux.c +++ b/lib/unistr/u8-uctomb-aux.c @@ -20,6 +20,14 @@ /* Specification. */ #include "unistr.h" +#ifndef FALLTHROUGH +# if __GNUC__ < 7 +# define FALLTHROUGH ((void) 0) +# else +# define FALLTHROUGH __attribute__ ((__fallthrough__)) +# endif +#endif + int u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n) { @@ -48,9 +56,9 @@ u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n) switch (count) /* note: code falls through cases! */ { case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; - /* fallthrough */ + FALLTHROUGH; case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; - /* fallthrough */ + FALLTHROUGH; case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0; /*case 1:*/ s[0] = uc; } diff --git a/tests/test-argp.c b/tests/test-argp.c index fe9c415239..04a0a90a16 100644 --- a/tests/test-argp.c +++ b/tests/test-argp.c @@ -26,6 +26,8 @@ # include #endif +#include "macros.h" + struct test_args { int test; @@ -63,7 +65,7 @@ group1_parser (int key, char *arg, struct argp_state *state) case 'r': args->read = 1; - /* fall through */ + FALLTHROUGH; case 'f': args->file = arg; break; diff --git a/tests/test-getopt.h b/tests/test-getopt.h index ce470c85e8..5c0e5b5aa3 100644 --- a/tests/test-getopt.h +++ b/tests/test-getopt.h @@ -17,6 +17,7 @@ /* Written by Bruno Haible , 2009. */ #include +#include "macros.h" /* The glibc/gnulib implementation of getopt supports setting optind = 0, but not all other implementations do. This matters for getopt. @@ -66,7 +67,7 @@ getopt_loop (int argc, const char **argv, ASSERT (options[0] == ':' || ((options[0] == '-' || options[0] == '+') && options[1] == ':')); - /* fall through */ + FALLTHROUGH; case '?': *unrecognized = optopt; break; diff --git a/tests/test-getopt_long.h b/tests/test-getopt_long.h index 670ef9c0d7..e90ebed984 100644 --- a/tests/test-getopt_long.h +++ b/tests/test-getopt_long.h @@ -87,7 +87,7 @@ getopt_long_loop (int argc, const char **argv, ASSERT (options[0] == ':' || ((options[0] == '-' || options[0] == '+') && options[1] == ':')); - /* fall through */ + FALLTHROUGH; case '?': *unrecognized = optopt; break; diff --git a/tests/test-tsearch.c b/tests/test-tsearch.c index 5cbf38de8b..9e77524f23 100644 --- a/tests/test-tsearch.c +++ b/tests/test-tsearch.c @@ -34,6 +34,8 @@ SIGNATURE_CHECK (twalk, void, (void const *, #include #include +#include "macros.h" + #define SEED 0 #if HAVE_TSEARCH /* The system's tsearch() is not expected to keep the tree balanced. */ @@ -234,7 +236,7 @@ mangle_tree (enum order how, enum action what, void **root, int lag) break; j = k; - /* fall through */ + FALLTHROUGH; case delete: elem = tfind (x + j, (void *const *) root, cmp_fn);