]> Savannah Git Hosting - gnulib.git/commitdiff
fallthrough: update for GCC 7/8
authorJim Meyering <meyering@fb.com>
Thu, 18 May 2017 15:36:27 +0000 (08:36 -0700)
committerJim Meyering <meyering@fb.com>
Fri, 19 May 2017 23:47:09 +0000 (16:47 -0700)
* 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.

ChangeLog
lib/freopen-safer.c
lib/fts.c
lib/quotearg.c
lib/unistr/u8-uctomb-aux.c
tests/test-argp.c
tests/test-getopt.h
tests/test-getopt_long.h
tests/test-tsearch.c

index 46714cdd49d034b62b1dcacc0cd16921dad6829e..807c8ed854874004139e99bdf92eb5b0fca48052 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2017-05-18  Jim Meyering  <meyering@fb.com>
+
+       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  <eggert@cs.ucla.edu>
 
        argp: fix shift bug
index 42dc39c7ddfd904b3b4336b9fd5f3c9a4ee03c52..be84ae68a2b37a0aae42b4d0148fe0a8d2199f17 100644 (file)
 #include <stdbool.h>
 #include <unistd.h>
 
+#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;
index fabaa97d189cbef4444154719b3c8d8042112c0b..3bac3244ea09abbc164309d192caa849840dec58 100644 (file)
--- 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 <https://bugzilla.redhat.com/1252549>
          NFS should return true.  However st_nlink values are not accurate on
          all implementations as per <https://bugzilla.redhat.com/1299169>.  */
-      /* fall through */
+      FALLTHROUGH;
     case S_MAGIC_PROC:
       /* Per <http://bugs.debian.org/143111> /proc may have
          bogus stat.st_nlink values.  */
-      /* fall through */
+      FALLTHROUGH;
     default:
       return false;
     }
index 26903c711aa7088c31d7b58669389df105e91a2d..f6570330b9338f689dfba489856edd5582021d39 100644 (file)
 
 #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 ';':
index b6adbe049a0d1d9a56b220f5eef0e0226064aeb4..72d35d814f83669b244c9ce06651c4935fb319bf 100644 (file)
 /* 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;
     }
index fe9c4152396b7f271fed743a08af5096eecf5990..04a0a90a1614e0e50ddd2de3bcba7c01f638ae94 100644 (file)
@@ -26,6 +26,8 @@
 # include <strings.h>
 #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;
index ce470c85e839b03b6e2ff7c087fc38b34ddb9db6..5c0e5b5aa314232fef4f602ce0e6df137add4955 100644 (file)
@@ -17,6 +17,7 @@
 /* Written by Bruno Haible <bruno@clisp.org>, 2009.  */
 
 #include <stdbool.h>
+#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;
index 670ef9c0d78235afbef9cf0f2a5e78e1ad01caa3..e90ebed9846b7ff139cc918ed77486875582865d 100644 (file)
@@ -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;
index 5cbf38de8b565a661ab81a411f3fe7aceae9b60e..9e77524f230d269001a3c338e218a87020f9bffb 100644 (file)
@@ -34,6 +34,8 @@ SIGNATURE_CHECK (twalk, void, (void const *,
 #include <stdlib.h>
 #include <string.h>
 
+#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);