bug-gnulib
[Top][All Lists]
Advanced

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

Re: inline -Werror=missing-declarations warnings


From: Pádraig Brady
Subject: Re: inline -Werror=missing-declarations warnings
Date: Tue, 18 Dec 2012 18:13:53 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 12/18/2012 03:16 AM, Paul Eggert wrote:
On 12/17/12 17:35, Pádraig Brady wrote:
Should the check in extern-inline.m4 be expanded to all __GNUC_?
39cedf6f said the issue was only with gcc 4.8, but
GCC 4.5.3 (on cygwin at least), seems to have the issue too.

If I understand things correctly, 39cedf6f relies on
_Pragma ("GCC diagnostic push"), which requires GCC 4.6
or later, and so we can't apply its idea to GCC 4.5.3.

Right.

The typical solution for older GCCs right now is to
ignore the bogus warnings that they generate, which
implies that with these older compilers one should either
avoid -Werror, or avoid -Wmissing-prototypes and
-Wmissing-declarations and -Wsuggest-attributes=const.

Well gnulib doesn't add -Werror.
It could disable that above with something like:

diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index f3cb23b..b02122d 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -90,6 +90,33 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
       CFLAGS="$gl_save_CFLAGS"])
     AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])

+    dnl Check if the compiler has fine-grained control over where
+    dnl diagnostics apply, so help determine wether to
+    dnl disable certain warnings.
+    AC_MSG_CHECKING([whether we have fine grained diagnostics])
+    AC_CACHE_VAL([gl_cv_cc_finegrained_diagnostics], [
+      gl_save_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -Werror -Wformat"
+      AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM(
+           [[#include <stdio.h>
+             int main(void)
+             {
+               float f=0; int unused;
+               #pragma GCC diagnostic ignored "-Wunused-variable"
+               #pragma GCC diagnostic push
+               #pragma GCC diagnostic ignored "-Wformat"
+               #pragma GCC diagnostic error   "-Wunused-variable"
+               printf ("%d\n", f);
+               #pragma GCC diagnostic pop
+               return 0;
+             }
+           ]],
+           [[]])],
+        [gl_cv_cc_finegrained_diagnostics=yes],
+        [gl_cv_cc_finegrained_diagnostics=no])
+      CFLAGS="$gl_save_CFLAGS"])
+    AC_MSG_RESULT([$gl_cv_cc_finegrained_diagnostics])
   fi

   # List all gcc warning categories.
@@ -220,5 +247,9 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
     gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
   fi

+  if test "$gl_cv_cc_finegrained_diagnostics" = no; then
+    gl_manywarn_set="$gl_manywarn_set -Wno-missing-declarations ..."
+  fi
+
   $1=$gl_manywarn_set
 ])


However that's a bit complicated. I wouldn't mind, apart from it would
need to be updated any time part of gnulib selectively disabled warnings using
#pragmas
So I'll probably not go with this, and do the following instead...

Z. Majeed wrote that he had to fiddle with --disable-gcc-warnings
(I assume he meant --enable-gcc-warnings?) and perhaps
--enable-gcc-warnings should be tweaked to disable these
problematic warnings with older compilers.

coreutils auto does --enable-gcc-warnings if
compiling from a directory with .git/ present.
So --disable-gcc-warnings is needed to avoid that.

While explicit version checks are not as robust
as feature checks, I don't see much advantage in
adjusting the above feature check patch for use in coreutils,
so instead I'll probably go with this simpler coreutils patch:

diff --git a/configure.ac b/configure.ac
index 6504144..295802d 100644
--- a/configure.ac
+++ b/configure.ac

AC_ARG_ENABLE([gcc-warnings]
...
+   # GCC provides fine-grained control over diagnostics which
+   # is used in gnulib for example to suppress warnings from
+   # certain sections of code.  So if this is available and
+   # we're running from a git repo, then auto enable the warnings.
+   gl_gcc_warnings=no
+   gl_GCC_VERSION_IFELSE([4], [6], [test -d "$srcdir"/.git && 
gl_gcc_warnings=yes])


thanks for the info,
Pádraig.



reply via email to

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