I tried to build the coreutils using very recent GCC 7, built from
latest git, and encountered a few new warnings (errors when configured
with --enable-gcc-warnings), so wrote the following to address them.
With these, everything now compiles warning free:

>From 35f28e3cdc0132ef87c5213e0c42b5b409d188d7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Mon, 3 Oct 2016 09:00:48 -0700
Subject: [PATCH 1/3] gnulib: update to latest and adapt printf-quote.sh test

* .gitignore: Add /lib/limits.h.
* tests/misc/printf-quote.sh: Reflect that a single quote is now
rendered as "'", rather than as ''\'''.
---
 .gitignore                 | 1 +
 gnulib                     | 2 +-
 tests/misc/printf-quote.sh | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 86574ec..388e664 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,6 +68,7 @@
 /lib/inttypes.h
 /lib/langinfo.h
 /lib/libcoreutils.a
+/lib/limits.h
 /lib/link-warning.h
 /lib/locale.h
 /lib/math.h
diff --git a/gnulib b/gnulib
index 6d237fd..7dad5f2 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 6d237fd01d98f2cdd588055a088fed39646ab82f
+Subproject commit 7dad5f25591de682c452c3fc39ffe2fa11e21491
diff --git a/tests/misc/printf-quote.sh b/tests/misc/printf-quote.sh
index 9636656..43b6dcc 100755
--- a/tests/misc/printf-quote.sh
+++ b/tests/misc/printf-quote.sh
@@ -25,7 +25,7 @@ prog='env printf'
 $prog '%q\n' '' "'" a 'a b' '~a' 'a~' "$($prog %b 'a\r')" > out
 cat <<\EOF > exp || framework_failure_
 ''
-''\'''
+"'"
 a
 'a b'
 '~a'
--
2.7.4


>From c7f3053869a26179efdff0f4d9652b3663d18fce Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Wed, 14 Sep 2016 11:48:33 -0700
Subject: [PATCH 2/3] maint: pr: avoid new GCC 7 warning

* src/pr.c (main): Avoid this warning from GCC 7:
src/pr.c:1119:6: error: assuming signed overflow does not occur when \
  simplifying conditional to constant [-Werror=strict-overflow]
   if (n_files == 0)
---
 src/pr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/pr.c b/src/pr.c
index d4549a3..a22d550 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -847,7 +847,7 @@ separator_string (const char *optarg_S)
 int
 main (int argc, char **argv)
 {
-  int n_files;
+  unsigned int n_files;
   bool old_options = false;
   bool old_w = false;
   bool old_s = false;
--
2.7.4


>From d087a87e5e3aceaaa31925d1a1523e08c3138e24 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Tue, 4 Oct 2016 19:20:46 -0700
Subject: [PATCH 3/3] build: add die.h; avoid new warnings from GCC 7

* src/die.h (die): New file/function from grep.
Note: we expect this file to migrate to gnulib.
* src/csplit.c: Include die.h.
(check_format_conv_type): Use die in place of error-nonzero;break;
* src/install.c (strip): Likewise.
* src/nl.c (proc_text): Likewise.  This also suppresses a new warning
from GCC 7's -Werror=strict-overflow.
* src/tail.c (parse_options): Likewise.
* src/basename.c (main): Adjust "fall through" comment
so that GCC 7's -Wimplicit-fallthrough honors it.
* src/cp.c (main): Add a "fall through" comment.
* src/ls.c (gobble_file): Likewise.
(get_funky_string): Adjust a "fall through" comment so it is
recognized.
* cfg.mk (exclude_file_name_regexp--sc_system_h_headers): Add die.h
to this list of exempt src/*.h files.
---
 cfg.mk         |  2 +-
 src/basename.c |  3 ++-
 src/cp.c       |  1 +
 src/csplit.c   |  4 ++--
 src/die.h      | 31 +++++++++++++++++++++++++++++++
 src/install.c  |  4 ++--
 src/ls.c       |  1 +
 src/nl.c       |  3 ++-
 src/tail.c     |  4 ++--
 9 files changed, 44 insertions(+), 9 deletions(-)
 create mode 100644 src/die.h

diff --git a/cfg.mk b/cfg.mk
index 08d9e9d..9acb42c 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -794,7 +794,7 @@ exclude_file_name_regexp--sc_bindtextdomain = \
 exclude_file_name_regexp--sc_trailing_blank = \
   ^(tests/pr/|gl/.*\.diff$$|man/help2man)
 exclude_file_name_regexp--sc_system_h_headers = \
-  ^src/((system|copy)\.h|make-prime-list\.c)$$
+  ^src/((die|system|copy)\.h|make-prime-list\.c)$$

 _src = (false|lbracket|ls-(dir|ls|vdir)|tac-pipe|uname-(arch|uname))
 exclude_file_name_regexp--sc_require_config_h_first = \
diff --git a/src/basename.c b/src/basename.c
index e2ed879..fe3cb3f 100644
--- a/src/basename.c
+++ b/src/basename.c
@@ -146,7 +146,8 @@ main (int argc, char **argv)
         {
         case 's':
           suffix = optarg;
-          /* Fall through: -s implies -a.  */
+          /* -s implies -a, so...  */
+          /* fall through */

         case 'a':
           multiple_names = true;
diff --git a/src/cp.c b/src/cp.c
index 13dc1ea..389e43e 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -1040,6 +1040,7 @@ main (int argc, char **argv)
               x.require_preserve = true;
               break;
             }
+          /* fall through */

         case 'p':
           x.preserve_ownership = true;
diff --git a/src/csplit.c b/src/csplit.c
index ac92d4c..30a97e5 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -28,6 +28,7 @@

 #include <regex.h>

+#include "die.h"
 #include "error.h"
 #include "fd-reopen.h"
 #include "quote.h"
@@ -1287,8 +1288,7 @@ check_format_conv_type (char *format, int flags)
       break;

     case 0:
-      error (EXIT_FAILURE, 0, _("missing conversion specifier in suffix"));
-      break;
+      die (EXIT_FAILURE, 0, _("missing conversion specifier in suffix"));

     default:
       if (isprint (ch))
diff --git a/src/die.h b/src/die.h
new file mode 100644
index 0000000..f64ab34
--- /dev/null
+++ b/src/die.h
@@ -0,0 +1,31 @@
+/* Report an error and exit.
+   Copyright 2016 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
+
+#ifndef DIE_H
+# define DIE_H
+
+# include <error.h>
+# include <stdbool.h>
+# include <verify.h>
+
+/* Like 'error (STATUS, ...)', except STATUS must be a nonzero constant.
+   This may pacify the compiler or help it generate better code.  */
+# define die(status, ...) \
+  verify_expr (status, (error (status, __VA_ARGS__), assume (false)))
+
+#endif /* DIE_H */
diff --git a/src/install.c b/src/install.c
index 1e1fed5..8f512d8 100644
--- a/src/install.c
+++ b/src/install.c
@@ -31,6 +31,7 @@
 #include "error.h"
 #include "cp-hash.h"
 #include "copy.h"
+#include "die.h"
 #include "filenamecat.h"
 #include "full-read.h"
 #include "mkancesdirs.h"
@@ -555,8 +556,7 @@ strip (char const *name)
       break;
     case 0:                    /* Child. */
       execlp (strip_program, strip_program, name, NULL);
-      error (EXIT_FAILURE, errno, _("cannot run %s"), quoteaf (strip_program));
-      break;
+      die (EXIT_FAILURE, errno, _("cannot run %s"), quoteaf (strip_program));
     default:                   /* Parent. */
       if (waitpid (pid, &status, 0) < 0)
         error (0, errno, _("waiting for strip"));
diff --git a/src/ls.c b/src/ls.c
index 28eff6f..4d6e647 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -3113,6 +3113,7 @@ gobble_file (char const *name, enum filetype type, ino_t 
inode,
                  directory, and --dereference-command-line-symlink-to-dir is
                  in effect.  Fall through so that we call lstat instead.  */
             }
+          /* fall through */

         default: /* DEREF_NEVER */
           err = lstat (absolute_name, &f->stat);
diff --git a/src/nl.c b/src/nl.c
index b276f09..9696526 100644
--- a/src/nl.c
+++ b/src/nl.c
@@ -27,6 +27,7 @@

 #include <regex.h>

+#include "die.h"
 #include "error.h"
 #include "fadvise.h"
 #include "linebuffer.h"
@@ -352,7 +353,7 @@ proc_text (void)
                          0, line_buf.length - 1, NULL))
         {
         case -2:
-          error (EXIT_FAILURE, errno, _("error in regular expression search"));
+          die (EXIT_FAILURE, errno, _("error in regular expression search"));

         case -1:
           fputs (print_no_line_fmt, stdout);
diff --git a/src/tail.c b/src/tail.c
index 545da03..4e98dd5 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -34,6 +34,7 @@
 #include "system.h"
 #include "argmatch.h"
 #include "c-strtod.h"
+#include "die.h"
 #include "error.h"
 #include "fcntl--.h"
 #include "isapipe.h"
@@ -2161,8 +2162,7 @@ parse_options (int argc, char **argv,

         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
-          error (EXIT_FAILURE, 0,
-                 _("option used in invalid context -- %c"), c);
+          die (EXIT_FAILURE, 0, _("option used in invalid context -- %c"), c);

         default:
           usage (EXIT_FAILURE);
--
2.7.4

Reply via email to