bug-coreutils
[Top][All Lists]
Advanced

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

[PATCH 4/4] maint: enable many gcc warnings


From: Jim Meyering
Subject: [PATCH 4/4] maint: enable many gcc warnings
Date: Mon, 02 Mar 2009 09:22:30 +0100

This turns on some new (to coreutils) gcc warnings and addresses
the ones that seemed useful and that didn't provoke too much noise.
The others are disabled in configure.ac.

This works for me with gcc-4.4.0 20090204, and is enabled only
with an explicit ./configure --enable-gcc-warnings.


>From 14cdeddbf39f8ffde844c6d28547b4c9d74cd362 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 14 Feb 2009 10:45:53 +0100
Subject: [PATCH 1/4] maint: cp: avoid gcc warning about unused macro definitions

* src/cp.c (INITIAL_HASH_MODULE, INITIAL_ENTRY_TAB_SIZE): Remove.
---
 src/cp.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/src/cp.c b/src/cp.c
index 57907cc..af4bd60 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -81,12 +81,6 @@ enum
   UNLINK_DEST_BEFORE_OPENING
 };

-/* Initial number of entries in each hash table entry's table of inodes.  */
-#define INITIAL_HASH_MODULE 100
-
-/* Initial number of entries in the inode hash table.  */
-#define INITIAL_ENTRY_TAB_SIZE 70
-
 /* True if the kernel is SELinux enabled.  */
 static bool selinux_enabled;

--
1.6.2.rc1.285.gc5f54


>From 2d10b7617bf846d197b881507c6c37e951e773dd Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 14 Feb 2009 11:26:14 +0100
Subject: [PATCH 2/4] maint: avoid warnings about potentially-counterproductive 
"inline"

* src/dd.c (quit): Remove "inline" attribute.
* src/test.c (advance, unary_advance): Likewise.
---
 src/dd.c   |    2 +-
 src/test.c |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/dd.c b/src/dd.c
index 6837b7b..e9a5504 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -669,7 +669,7 @@ cleanup (void)
           _("closing output file %s"), quote (output_file));
 }

-static inline void ATTRIBUTE_NORETURN
+static void ATTRIBUTE_NORETURN
 quit (int code)
 {
   cleanup ();
diff --git a/src/test.c b/src/test.c
index b670909..1825e90 100644
--- a/src/test.c
+++ b/src/test.c
@@ -91,7 +91,7 @@ test_syntax_error (char const *format, char const *arg)
    past the end of the argument list.  This check is supressed if the
    argument is false.  */

-static inline void
+static void
 advance (bool f)
 {
   ++pos;
@@ -100,7 +100,7 @@ advance (bool f)
     beyond ();
 }

-static inline void
+static void
 unary_advance (void)
 {
   advance (true);
@@ -567,9 +567,9 @@ test_unop (char const *op)
     case 'u': case 'w': case 'x': case 'z':
     case 'G': case 'L': case 'O': case 'S': case 'N':
       return true;
+    default:
+      return false;
     }
-
-  return false;
 }

 static bool
--
1.6.2.rc1.285.gc5f54


>From ebfbdf9f0e53d5eb8e6a1c85d825a1a9f0f1baef Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 14 Feb 2009 11:22:22 +0100
Subject: [PATCH 3/4] maint: avoid gcc warning about missing attributes

* src/prog-fprintf.h (prog_fprintf): Declare with printf attribute.
* src/system.h (usage): Declare with the "noreturn" attribute.
---
 src/prog-fprintf.h |    5 +++--
 src/system.h       |    2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/prog-fprintf.h b/src/prog-fprintf.h
index d5c3d42..98029ab 100644
--- a/src/prog-fprintf.h
+++ b/src/prog-fprintf.h
@@ -1,5 +1,5 @@
 /* prog-fprintf.h - common formating output functions and definitions
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 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
@@ -19,6 +19,7 @@

 # include <stdio.h>

-extern void prog_fprintf (FILE *fp, char const *fmt, ...);
+extern void prog_fprintf (FILE *fp, char const *fmt, ...)
+  __attribute__ ((__format__ (__printf__, 2, 3)));

 #endif
diff --git a/src/system.h b/src/system.h
index 990be0c..ba74da4 100644
--- a/src/system.h
+++ b/src/system.h
@@ -655,4 +655,4 @@ bad_cast (char const *s)
   return (char *) s;
 }

-void usage (int status);
+void usage (int status) ATTRIBUTE_NORETURN;
--
1.6.2.rc1.285.gc5f54


>From 6449370e9e07939712bbe0ebfad38ad78ab69097 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 14 Feb 2009 11:29:20 +0100
Subject: [PATCH 4/4] maint: enable many gcc warnings

* bootstrap.conf (gnulib_modules): Add manywarnings.
* configure.ac: Use gl_MANYWARN_ALL_GCC, and exclude options
I don't want or that provoke too many warnings.
(WARN_CFLAGS, WERROR_CFLAGS): Define.
(lint, GNULIB_PORTCHECK): Define.
(_FORTIFY_SOURCE): Define to 2.
---
 bootstrap.conf |    1 +
 configure.ac   |   57 ++++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 89564fe..9c385e4 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -67,6 +67,7 @@ gnulib_modules="
        inttostr inttypes isapipe
        lchmod lchown lib-ignore linebuffer link-follow
        long-options lstat malloc
+       manywarnings
        mbrtowc
        mbswidth
        memcasecmp mempcpy
diff --git a/configure.ac b/configure.ac
index 99452c8..f10191f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
 # -*- autoconf -*-
 # Process this file with autoconf to produce a configure script.

-# Copyright (C) 1991, 1993-2008 Free Software Foundation, Inc.
+# Copyright (C) 1991, 1993-2009 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
@@ -58,23 +58,52 @@ AC_ARG_ENABLE([gcc-warnings],
 if test "$gl_gcc_warnings" = yes; then
   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
   AC_SUBST([WERROR_CFLAGS])
-  gl_WARN_ADD([-Wall])
-  gl_WARN_ADD([-Wextra])
-  gl_WARN_ADD([-Wshadow])
-  gl_WARN_ADD([-Wno-sign-compare])
-  gl_WARN_ADD([-Wformat])
-  gl_WARN_ADD([-Wformat-security])
-  gl_WARN_ADD([-Wcast-align])
-  gl_WARN_ADD([-Wpointer-arith])
-  gl_WARN_ADD([-Wwrite-strings])
-  gl_WARN_ADD([-Wbad-function-cast])
-  gl_WARN_ADD([-Wmissing-declarations])
-  gl_WARN_ADD([-Wmissing-prototypes])
-  gl_WARN_ADD([-Wstrict-prototypes])
+
+  # Add many warnings, except some...
+  nw="$nw -Wdeclaration-after-statement" # too useful to forbid
+  nw="$nw -Waggregate-return"       # anachronistic
+  nw="$nw -Wc++-compat"             # We don't care about C++ compilers
+  nw="$nw -Wundef"                  # Warns on '#if GNULIB_FOO' etc in gnulib
+  nw="$nw -Wtraditional"            # Warns on #elif which we use often
+  nw="$nw -Wcast-qual"              # Too many warnings for now
+  nw="$nw -Wconversion"             # Too many warnings for now
+  nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
+  nw="$nw -Wsign-conversion"        # Too many warnings for now
+  nw="$nw -Wtraditional-conversion" # Too many warnings for now
+  nw="$nw -Wunreachable-code"       # Too many warnings for now
+  nw="$nw -Wpadded"                 # Our structs are not padded
+  nw="$nw -Wredundant-decls"        # openat.h declares e.g., mkdirat
+  nw="$nw -Wlogical-op"             # any use of fwrite provokes this
+  nw="$nw -Wformat-nonliteral"      # who.c and pinky.c strftime uses
+  nw="$nw -Wvla"                    # warnings in gettext.h
+  nw="$nw -Wnested-externs"         # use of XARGMATCH/verify_function__
+  nw="$nw -Wswitch-enum"            # Too many warnings for now
+  nw="$nw -Wswitch-default"         # Too many warnings for now
+  # things I might fix soon:
+  nw="$nw -Wfloat-equal"            # sort.c, seq.c
+  nw="$nw -Wmissing-format-attribute" # copy.c
+  nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
+  nw="$nw -Winline"                 # system.h's 
readdir_ignoring_dot_and_dotdot
+  nw="$nw -Wstrict-overflow"        # expr.c, pr.c, tr.c, factor.c
+  # ?? -Wstrict-overflow
+
+  gl_MANYWARN_ALL_GCC([ws])
+  gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
+  for w in $ws; do
+    gl_WARN_ADD([$w])
+  done
+  gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one
+  gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
+  gl_WARN_ADD([-Wno-pointer-sign])     # Too many warnings for now
+  gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
+  gl_WARN_ADD([-fdiagnostics-show-option])
+
   AC_SUBST([WARN_CFLAGS])
+
   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
   AC_DEFINE([_FORTIFY_SOURCE], [2],
     [enable compile-time and run-time bounds-checking, and some warnings])
+  AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
 fi

 AC_FUNC_FORK
--
1.6.2.rc1.285.gc5f54




reply via email to

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