bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] manywarnings: update for GCC 7


From: Paul Eggert
Subject: [PATCH] manywarnings: update for GCC 7
Date: Tue, 16 May 2017 09:32:46 -0700

* build-aux/gcc-warning.spec:
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC):
Add GCC 7 warnings, notably -Wimplicit-fallthrough=5, which
requires a non-comment fallthrough attribute.  This is a bit
cleaner than the comment versions.
* lib/strftime.c, lib/dfa.c, lib/fnmatch.c, lib/mbrtowc.c:
* lib/vasnprintf.c, tests/macros.h (FALLTHROUGH): New macro.
Use it whenever one switch case falls through into the next.
---
 ChangeLog                  | 12 ++++++++++++
 build-aux/gcc-warning.spec | 30 ++++++++++++++++++++++++++++--
 lib/dfa.c                  | 20 +++++++++++++-------
 lib/fnmatch.c              |  8 ++++++++
 lib/fnmatch_loop.c         |  8 +++-----
 lib/mbrtowc.c              | 11 +++++++++--
 lib/strftime.c             | 13 ++++++++++---
 lib/vasnprintf.c           | 10 +++++++++-
 m4/manywarnings.m4         | 25 ++++++++++++++++++++++---
 tests/macros.h             |  8 ++++++++
 tests/test-mbrtowc.c       |  2 +-
 tests/test-sigpipe.c       |  4 +++-
 12 files changed, 126 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2fa97a2..ec82d08 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-05-16  Paul Eggert  <address@hidden>
+
+       manywarnings: update for GCC 7
+       * build-aux/gcc-warning.spec:
+       * m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC):
+       Add GCC 7 warnings, notably -Wimplicit-fallthrough=5, which
+       requires a non-comment fallthrough attribute.  This is a bit
+       cleaner than the comment versions.
+       * lib/strftime.c, lib/dfa.c, lib/fnmatch.c, lib/mbrtowc.c:
+       * lib/vasnprintf.c, tests/macros.h (FALLTHROUGH): New macro.
+       Use it whenever one switch case falls through into the next.
+
 2017-05-15  Bruno Haible  <address@hidden>
 
        gnulib-tool: Fix generated code when libtests contains module 'alloca'.
diff --git a/build-aux/gcc-warning.spec b/build-aux/gcc-warning.spec
index 8c39017..9b9c39f 100644
--- a/build-aux/gcc-warning.spec
+++ b/build-aux/gcc-warning.spec
@@ -6,7 +6,14 @@
 -Waggregate-return                     obsolescent
 -Waliasing                             fortran
 -Walign-commons                                fortran
+-Waligned-new                          c++
+-Waligned-new=[none|global|all]                c++
+-Walloca                               we like alloca in small doses
+-Walloca-larger-than=<number>          FIXME: choose something sane?
+-Walloc-size-larger-than=              handled specially by gl_MANYWARN_ALL_GCC
+-Walloc-zero                           Gnulib fixes this problem
 -Wampersand                            fortran
+-Wargument-mismatch                    fortran
 -Warray-bounds                         covered by -Warray-bounds=
 -Warray-bounds=                                handled specially by 
gl_MANYWARN_ALL_GCC
 -Warray-temporaries                    fortran
@@ -15,6 +22,8 @@
 -Wc++0x-compat                         c++
 -Wc++11-compat                         c++
 -Wc++14-compat                         c++
+-Wc++17-compat                         c++
+-Wc++1z-compat                         c++
 -Wc-binding-type                       fortran
 -Wc90-c99-compat                       c compatibility
 -Wc99-c11-compat                       c compatibility
@@ -35,8 +44,14 @@
 -Wfloat-equal                          FIXME maybe? borderline.  some will 
want this
 -Wformat                               covered by -Wformat=2
 -Wformat=                              gcc --help=warnings artifact
+-Wformat-overflow                      covered by -Wformat-overflow=2
+-Wformat-overflow=                     handled specially by gl_MANYWARN_ALL_GCC
+-Wformat-truncation                    covered by -Wformat-truncation=2
+-Wformat-truncation=                   handled specially by gl_MANYWARN_ALL_GCC
 -Wframe-larger-than=<number>           FIXME: choose something sane?
 -Wfunction-elimination                 fortran
+-Wimplicit-fallthrough                 covered by -Wimplicit-fallthrough=2
+-Wimplicit-fallthrough=                        handled specially by 
gl_MANYWARN_ALL_GCC
 -Wimplicit-interface                   fortran
 -Wimplicit-procedure                   fortran
 -Winherited-variadic-ctor              c++
@@ -55,10 +70,11 @@
 -Wmultiple-inheritance                 c++ and objc++
 -Wnamespaces                           c++
 -Wnoexcept                             c++
+-Wnoexcept-type                                c++
 -Wnon-template-friend                  c++
 -Wnon-virtual-dtor                     c++
 -Wnormalized                           covered by -Wnormalized=
--Wnormalized=<none|id|nfc|nfkc>                handled specially by 
gl_MANYWARN_ALL_GCC
+-Wnormalized=[none|id|nfc|nfkc]                handled specially by 
gl_MANYWARN_ALL_GCC
 -Wold-style-cast                       c++ and objc++
 -Woverloaded-virtual                   c++
 -Woverride-init-side-effects           c++ and objc++
@@ -73,20 +89,28 @@
 -Wrealloc-lhs                          fortran
 -Wrealloc-lhs-all                      fortran
 -Wredundant-decls                      FIXME maybe? many _gl_cxxalias_dummy FPs
+-Wregister                             c++ and objc++
 -Wreorder                              c++ and objc++
 -Wselector                             objc and objc++
 -Wshadow-ivar                          objc
+-Wshadow=compatible-local              covered by -Wshadow
+-Wshadow-compatible-local              covered by -Wshadow
+-Wshadow=global                                covered by -Wshadow
+-Wshadow=local                         covered by -Wshadow
+-Wshadow-local                         covered by -Wshadow
 -Wshift-overflow                       covered by -Wshift-overflow=2
 -Wshift-overflow=                      gcc --help=warnings artifact
 -Wsign-compare                         FIXME maybe? borderline.  some will 
want this
 -Wsign-conversion                      FIXME maybe? borderline.  some will 
want this
 -Wsign-promo                           c++ and objc++
 -Wsized-deallocation                   c++ and objc++
--Wstack-usage=                         FIXME: choose something sane?
+-Wstack-usage=<number>                 FIXME: choose something sane?
 -Wstrict-aliasing=                     FIXME: choose something sane?
 -Wstrict-null-sentinel                 c++ and objc++
 -Wstrict-overflow=                     FIXME: choose something sane?
 -Wstrict-selector-match                        objc and objc++
+-Wstringop-overflow                    covered by -Wstringop-overflow=
+-Wstringop-overflow=                   handled specially by gl_MANYWARN_ALL_GCC
 -Wsubobject-linkage                    c++ and objc++
 -Wsuggest-override                     c++ and objc++
 -Wsurprising                           fortran
@@ -100,6 +124,7 @@
 -Wtraditional-conversion               obsolescent
 -Wundeclared-selector                  objc and objc++
 -Wundef                                        FIXME maybe? too many false 
positives
+-Wundefined-do-loop                    fortran
 -Wunderflow                            fortran
 -Wunreachable-code                     obsolescent no-op
 -Wunsuffixed-float-constants           triggers warning in gnulib's timespec.h
@@ -110,6 +135,7 @@
 -Wuseless-cast                         c++ and objc++
 -Wvirtual-inheritance                  c++
 -Wvirtual-move-assign                  c++
+-Wvla-larger-than=<number>             handled specially by gl_MANYWARN_ALL_GCC
 -Wzero-as-null-pointer-constant                c++ and objc++
 -Wzerotrip                             fortran
 -frequire-return-statement             go
diff --git a/lib/dfa.c b/lib/dfa.c
index e97dae1c..e08e63a 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -54,6 +54,14 @@ isasciidigit (char c)
 #include "xalloc.h"
 #include "localeinfo.h"
 
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
 #ifndef MIN
 # define MIN(a,b) ((a) < (b) ? (a) : (b))
 #endif
@@ -1614,10 +1622,10 @@ addtok_mb (struct dfa *dfa, token t, char mbprop)
 
     case BACKREF:
       dfa->fast = false;
-      /* fallthrough */
+      FALLTHROUGH;
     default:
       dfa->nleaves++;
-      /* fallthrough */
+      FALLTHROUGH;
     case EMPTY:
       dfa->parse.depth++;
       break;
@@ -2414,8 +2422,7 @@ dfaanalyze (struct dfa *d, bool searchflag)
                 copy (&merged, &d->follows[pos[j].index]);
               }
           }
-          /* fallthrough */
-
+          FALLTHROUGH;
         case QMARK:
           /* A QMARK or STAR node is automatically nullable.  */
           if (d->tokens[i] != PLUS)
@@ -3331,8 +3338,7 @@ dfa_supported (struct dfa const *d)
         case NOTLIMWORD:
           if (!d->localeinfo.multibyte)
             continue;
-          /* fallthrough */
-
+          FALLTHROUGH;
         case BACKREF:
         case MBCSET:
           return false;
@@ -3441,7 +3447,7 @@ dfassbuild (struct dfa *d)
               sup->tokens[j++] = EMPTY;
               break;
             }
-          /* fallthrough */
+          FALLTHROUGH;
         default:
           sup->tokens[j++] = d->tokens[i];
           if ((0 <= d->tokens[i] && d->tokens[i] < NOTCHAR)
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 90134bd..3a63f35 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -65,6 +65,14 @@ extern int fnmatch (const char *pattern, const char *string, 
int flags);
 
 #include "flexmember.h"
 
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
 /* We often have to test for FNM_FILE_NAME and FNM_PERIOD being both set.  */
 #define NO_LEADING_PERIOD(flags) \
   ((flags & (FNM_FILE_NAME | FNM_PERIOD)) == (FNM_FILE_NAME | FNM_PERIOD))
diff --git a/lib/fnmatch_loop.c b/lib/fnmatch_loop.c
index 9f3c2e8..aed847d 100644
--- a/lib/fnmatch_loop.c
+++ b/lib/fnmatch_loop.c
@@ -960,7 +960,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR 
*string_end,
               new_no_leading_period = true;
               break;
             }
-          /* FALLTHROUGH */
+          FALLTHROUGH;
         default:
         normal_match:
           if (n == string_end || c != FOLD ((UCHAR) *n))
@@ -1114,8 +1114,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, 
const CHAR *string_end,
     case L_('*'):
       if (FCT (p, string, string_end, no_leading_period, flags) == 0)
         return 0;
-      /* FALLTHROUGH */
-
+      FALLTHROUGH;
     case L_('+'):
       do
         {
@@ -1151,8 +1150,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, 
const CHAR *string_end,
     case L_('?'):
       if (FCT (p, string, string_end, no_leading_period, flags) == 0)
         return 0;
-      /* FALLTHROUGH */
-
+      FALLTHROUGH;
     case L_('@'):
       do
         /* I cannot believe it but 'strcat' is actually acceptable
diff --git a/lib/mbrtowc.c b/lib/mbrtowc.c
index d4809f6..7415fff 100644
--- a/lib/mbrtowc.c
+++ b/lib/mbrtowc.c
@@ -35,6 +35,13 @@
 # include "streq.h"
 # include "verify.h"
 
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
 
 verify (sizeof (mbstate_t) >= 4);
 
@@ -74,10 +81,10 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t 
*ps)
         break;
       case 3:
         buf[2] = pstate[3];
-        /*FALLTHROUGH*/
+        FALLTHROUGH;
       case 2:
         buf[1] = pstate[2];
-        /*FALLTHROUGH*/
+        FALLTHROUGH;
       case 1:
         buf[0] = pstate[1];
         p = buf;
diff --git a/lib/strftime.c b/lib/strftime.c
index 8091f3d..e05c872 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -68,6 +68,14 @@ extern char *tzname[];
 #include <string.h>
 #include <stdbool.h>
 
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
 #ifdef COMPILE_WIDE
 # include <endian.h>
 # define CHAR_T wchar_t
@@ -1138,8 +1146,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
 #ifndef _NL_CURRENT
           format_char = L_('p');
 #endif
-          /* FALLTHROUGH */
-
+          FALLTHROUGH;
         case L_('p'):
           if (change_case)
             {
@@ -1474,7 +1481,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG 
(size_t maxsize)
 
         case L_('\0'):          /* GNU extension: % at end of format.  */
             --f;
-            /* Fall through.  */
+            FALLTHROUGH;
         default:
           /* Unknown format; output the format, including the '%',
              since this is most likely the right thing to do if a
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 839f790..9c2af0e 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -118,6 +118,14 @@
 # include "fpucw.h"
 #endif
 
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
 /* Default parameters.  */
 #ifndef VASNPRINTF
 # if WIDE_CHAR_VERSION
@@ -4837,7 +4845,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                     *fbp++ = 'l';
 # endif
 #endif
-                    /*FALLTHROUGH*/
+                    FALLTHROUGH;
                   case TYPE_LONGINT:
                   case TYPE_ULONGINT:
 #if HAVE_WINT_T
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index 0f06ade..2d35eff 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -99,12 +99,11 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
   # comm -3 \
   #  <(sed -n 's/^  *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
   #  <(gcc --help=warnings | sed -n 's/^  \(-[^ ]*\) .*/\1/p' | sort |
-  #      grep -v -x -f <(
+  #      grep -v -x -F -f <(
   #         awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
 
   gl_manywarn_set=
-  for gl_manywarn_item in \
-    -fno-common \
+  for gl_manywarn_item in -fno-common \
     -W \
     -Wabi \
     -Waddress \
@@ -113,6 +112,8 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
     -Wattributes \
     -Wbad-function-cast \
     -Wbool-compare \
+    -Wbool-operation \
+    -Wbuiltin-declaration-mismatch \
     -Wbuiltin-macro-redefined \
     -Wcast-align \
     -Wchar-subscripts \
@@ -122,6 +123,7 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
     -Wcomments \
     -Wcoverage-mismatch \
     -Wcpp \
+    -Wdangling-else \
     -Wdate-time \
     -Wdeprecated \
     -Wdeprecated-declarations \
@@ -131,10 +133,13 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
     -Wdiscarded-qualifiers \
     -Wdiv-by-zero \
     -Wdouble-promotion \
+    -Wduplicated-branches \
     -Wduplicated-cond \
+    -Wduplicate-decl-specifier \
     -Wempty-body \
     -Wendif-labels \
     -Wenum-compare \
+    -Wexpansion-to-defined \
     -Wextra \
     -Wformat-contains-nul \
     -Wformat-extra-args \
@@ -155,6 +160,7 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
     -Winit-self \
     -Winline \
     -Wint-conversion \
+    -Wint-in-bool-context \
     -Wint-to-pointer-cast \
     -Winvalid-memory-model \
     -Winvalid-pch \
@@ -163,6 +169,7 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
     -Wlogical-op \
     -Wmain \
     -Wmaybe-uninitialized \
+    -Wmemset-elt-size \
     -Wmemset-transposed-args \
     -Wmisleading-indentation \
     -Wmissing-braces \
@@ -188,9 +195,12 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
     -Wpacked-bitfield-compat \
     -Wparentheses \
     -Wpointer-arith \
+    -Wpointer-compare \
     -Wpointer-sign \
     -Wpointer-to-int-cast \
     -Wpragmas \
+    -Wpsabi \
+    -Wrestrict \
     -Wreturn-local-addr \
     -Wreturn-type \
     -Wscalar-storage-order \
@@ -214,6 +224,7 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
     -Wswitch \
     -Wswitch-bool \
     -Wswitch-default \
+    -Wswitch-unreachable \
     -Wsync-nand \
     -Wsystem-headers \
     -Wtautological-compare \
@@ -247,10 +258,18 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
 
   # gcc --help=warnings outputs an unusual form for these options; list
   # them here so that the above 'comm' command doesn't report a false match.
+  # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal:
+  ptrdiff_max_max=9223372036854775807
+  gl_manywarn_set="$gl_manywarn_set -Walloc-size-larger-than=$ptrdiff_max_max"
   gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
+  gl_manywarn_set="$gl_manywarn_set -Wformat-overflow=2"
+  gl_manywarn_set="$gl_manywarn_set -Wformat-truncation=2"
+  gl_manywarn_set="$gl_manywarn_set -Wimplicit-fallthrough=5"
   gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
   gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
+  gl_manywarn_set="$gl_manywarn_set -Wstringop-overflow=2"
   gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
+  gl_manywarn_set="$gl_manywarn_set -Wvla-larger-than=4031"
 
   # These are needed for older GCC versions.
   if test -n "$GCC"; then
diff --git a/tests/macros.h b/tests/macros.h
index 53b270c..0423d06 100644
--- a/tests/macros.h
+++ b/tests/macros.h
@@ -21,6 +21,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
 /* Define ASSERT_STREAM before including this file if ASSERT must
    target a stream other than stderr.  */
 #ifndef ASSERT_STREAM
diff --git a/tests/test-mbrtowc.c b/tests/test-mbrtowc.c
index ddbe243..70c8a2a 100644
--- a/tests/test-mbrtowc.c
+++ b/tests/test-mbrtowc.c
@@ -75,7 +75,7 @@ main (int argc, char *argv[])
         default:
           if (! (c && 1 < argc && argv[1][0] == '5'))
             break;
-          /* Fall through.  */
+          FALLTHROUGH;
         case '\t': case '\v': case '\f':
         case ' ': case '!': case '"': case '#': case '%':
         case '&': case '\'': case '(': case ')': case '*':
diff --git a/tests/test-sigpipe.c b/tests/test-sigpipe.c
index 48b22f1..e75372d 100644
--- a/tests/test-sigpipe.c
+++ b/tests/test-sigpipe.c
@@ -26,6 +26,8 @@ int s = SIGPIPE;
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "macros.h"
+
 static void
 handler (int sig)
 {
@@ -57,7 +59,7 @@ main (int argc, char **argv)
             case 'B': /* The write() call should have failed with EPIPE.  */
               if (ret < 0 && errno == EPIPE)
                 exit (0);
-              /*FALLTHROUGH*/
+              FALLTHROUGH;
             case 'A': /* The process should silently die.  */
             case 'C': /* The handler should have been called.  */
               fprintf (stderr, "write() returned %d with error %d.\n", ret, 
errno);
-- 
2.9.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]