schwehr / hdf5-old

Hierarchical Data Format (HDF) 5
Other
0 stars 0 forks source link

autoconf AC_C_INLINE with -Werror #18

Open schwehr opened 10 years ago

schwehr commented 10 years ago

Sub-bug to #17

http://lists.gnu.org/archive/html/bug-autoconf/2014-06/msg00002.html

diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index b58e42d..6779407 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1742,7 +1742,7 @@ for ac_kw in inline __inline__ __inline; do
 [#ifndef __cplusplus
 typedef int foo_t;
 static $ac_kw foo_t static_foo () {return 0; }
-$ac_kw foo_t foo () {return 0; }
+$ac_kw foo_t foo () {return static_foo(); }
 #endif
 ])],
                    [ac_cv_c_inline=$ac_kw])

Found via:

wget ftp://ftp.hdfgroup.uiuc.edu/pub/outgoing/hdf5/snapshots/v19/hdf5-1.9.182.tar.bz2

tar xf hdf5-1.9.182.tar.bz2
mkdir build && cd build
CPPFLAGS="-Werror -Wall -Wextra" ../hdf5-1.9.182/configure --enable-shared --enable-cxx --with-zlib=/usr --without-mpe --with-szlib=/sw --without-pthread --disable-parallel --enable-build-all --enable-maintainer-mode --enable-codestack --enable-debug=all --disable-silent-rules
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by HDF5 configure 1.9.182, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  $ ../hdf5-1.9.182/configure --enable-shared --enable-cxx --with-zlib=/usr --without-mpe --with-szlib=/sw --without-pthread --disable-parallel --enable-build-all --enable-maintainer-mode --enable-codestack --enable-debug=all --disable-silent-rules

[SNIP]

configure:27495: clang -c          -Werror=unused-variable -Wall -Wextra -I/sw/include conftest.c >&5
configure:27495: $? = 0
configure:27502: result: yes
configure:27510: checking for inline
configure:27526: clang -c          -Werror=unused-variable -Wall -Wextra -I/sw/include conftest.c >&5
conftest.c:132:21: warning: unused function 'static_foo' [-Wunused-function]
static inline foo_t static_foo () {return 0; }
                    ^
1 warning generated.
configure:27526: $? = 0
configure:27534: result: inline

configure.ac has:

## ----------------------------------------------------------------------
## Check compiler characteristics
##
AC_C_CONST
AC_C_INLINE
schwehr commented 10 years ago

http://lists.gnu.org/archive/html/bug-autoconf/2014-06/msg00007.html By Eric Blake:

On 06/09/2014 09:59 AM, Kurt Schwehr wrote:

Eric,

Thanks for the feedback. I definitely had the feeling that it would be impossible to get rid of all warnings for all compilers.

Two questions back at you:

1) Do you have a example of a source package that handles -Werror in a clean way so that I can use it a s model try to add the same to these other packages?

Sure. GNU coreutils:

http://git.savannah.gnu.org/cgit/coreutils.git/tree/configure.ac#n108 http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/local.mk

Note how it probes for -Werror separately from other flags, and sticks the result in a different variable for substitution at make time. At maketime, it then avoids -Werror for gnulib (which has a looser set of standards, and therefore fails some of the warning flags that coreutils turns on for itself), and enables -Werror for itself (all according to whether warnings-as-errors was requested based on configure options, which in turn have a default based on whether it detects a build from git sources or from a tarball).

2) Does the suggested fix I gave make sense? I think that means: a) It's not going to break any environments without -Werror or equivalent for compilers out there. b) It will generally reduce the number of compilers/flag combinations that would issue a warning for this test? If this proposed fix is a bad idea, why is it bad?

Your fix is a one-liner, and easy to maintain, once you resubmit it without the syntax error of a missing (); so I see no reason against applying your patch. I'm just pointing out that expecting -Werror to work during configure is a lost cause, and that while we can apply simple patches, we cannot solve the inherent technical problem of being able to make ALL compilers warning-free.

schwehr commented 10 years ago

Patch submitted to autoconf-patches:

http://lists.gnu.org/archive/html/autoconf-patches/2014-06/msg00002.html