]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Build: Silence two Autoconf warnings.
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 26 Sep 2023 10:14:37 +0000 (13:14 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 26 Sep 2023 10:50:19 +0000 (13:50 +0300)
There were two uses of AC_COMPILE_IFELSE that didn't use
AC_LANG_SOURCE and Autoconf warned about these. The omission
had been intentional but it turned out that this didn't do
what I thought it would.

Autoconf 2.71 manual gives an impression that AC_LANG_SOURCE
inserts all #defines that have been made with AC_DEFINE so
far (confdefs.h). The idea was that omitting AC_LANG_SOURCE
would mean that only the exact code included in the
AC_COMPILE_IFELSE call would be compiled.

With C programs this is not true: the #defines get added without
AC_LANG_SOURCE too. There seems to be no neat way to avoid this.
Thus, with the C language at least, adding AC_LANG_SOURCE makes
no other difference than silencing a warning from Autoconf. The
generated "configure" remains identical. (Docs of AC_LANG_CONFTEST
say that the #defines have been inserted since Autoconf 2.63b and
that AC_COMPILE_IFELSE uses AC_LANG_CONFTEST. So the behavior is
documented if one also reads the docs of macros that one isn't
calling directly.)

Any extra code, including #defines, can cause problems for
these two tests because these tests must use -Werror.
CC=clang CFLAGS=-Weverything is the most extreme example.
It enables -Wreserved-macro-identifier which warns about
#define __EXTENSIONS__ 1 because it begins with two underscores.
It's possible to write a test file that passes -Weverything but
it becomes impossible when Autoconf inserts confdefs.h.

So this commit adds AC_LANG_SOURCE to silence Autoconf warnings.
A different solution is needed for -Werror tests.

configure.ac

index 78d6e8acd5e3eb15415e172a6e94e9ae9cf58269..83d28b852eab5e64e64f8e63aa4d6953c7caeb56 100644 (file)
@@ -834,15 +834,14 @@ AC_C_BIGENDIAN
 # Use -Werror because some compilers accept unknown attributes and just
 # give a warning. If it works this should give no warnings, even
 # clang -Weverything should be fine.
-# dnl This doesn't need AC_LANG_SOURCE, minimal code is enough.
 AC_MSG_CHECKING([if __attribute__((__constructor__)) can be used])
 have_func_attribute_constructor=no
 OLD_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -Werror"
-AC_COMPILE_IFELSE([
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
        __attribute__((__constructor__))
        static void my_constructor_func(void) { return; }
-], [
+]])], [
        AC_DEFINE([HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR], [1],
                [Define to 1 if __attribute__((__constructor__))
                is supported for functions.])
@@ -878,12 +877,12 @@ if test "x$enable_ifunc" = xyes ; then
        OLD_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS -Werror"
        AC_MSG_CHECKING([if __attribute__((__ifunc__())) can be used])
-       AC_COMPILE_IFELSE([
+       AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
                static void func(void) { return; }
                static void (*resolve_func (void)) (void) { return func; }
                void func_ifunc (void)
                                __attribute__((__ifunc__("resolve_func")));
-       ], [
+       ]])], [
                AC_DEFINE([HAVE_FUNC_ATTRIBUTE_IFUNC], [1],
                        [Define to 1 if __attribute__((__ifunc__()))
                        is supported for functions.])