3 dnl Copyright (C) 2009-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl This file must be named something that sorts before all other
9 dnl gnulib-provided .m4 files. It is needed until the clang fix has
10 dnl been included in Autoconf.
12 # The following definitions arrange to use a compiler option
13 # -Werror=implicit-function-declaration in AC_CHECK_DECL, when the
14 # compiler is clang. Without it, clang implicitly declares "known"
15 # library functions in C mode, but not in C++ mode, which would cause
16 # Gnulib to omit a declaration and thus later produce an error in C++
17 # mode. As of clang 9.0, these "known" functions are identified through
18 # LIBBUILTIN invocations in the LLVM source file
19 # llvm/tools/clang/include/clang/Basic/Builtins.def.
20 # It's not possible to AC_REQUIRE the extra tests from AC_CHECK_DECL,
21 # because AC_CHECK_DECL, like other Autoconf built-ins, is not supposed
22 # to AC_REQUIRE anything: some configure.ac files have their first
23 # AC_CHECK_DECL executed conditionally. Therefore append the extra tests
25 AC_DEFUN([gl_COMPILER_CLANG],
27 dnl AC_REQUIRE([AC_PROG_CC])
28 AC_CACHE_CHECK([whether the compiler is clang],
29 [gl_cv_compiler_clang],
30 [dnl Use _AC_COMPILE_IFELSE instead of AC_EGREP_CPP, to avoid error
31 dnl "circular dependency of AC_LANG_COMPILER(C)" if AC_PROG_CC has
32 dnl not yet been invoked.
40 [gl_cv_compiler_clang=no],
41 [gl_cv_compiler_clang=yes])
44 AC_DEFUN([gl_COMPILER_PREPARE_CHECK_DECL],
46 dnl AC_REQUIRE([AC_PROG_CC])
47 dnl AC_REQUIRE([gl_COMPILER_CLANG])
48 AC_CACHE_CHECK([for compiler option needed when checking for declarations],
49 [gl_cv_compiler_check_decl_option],
50 [if test $gl_cv_compiler_clang = yes; then
51 dnl Test whether the compiler supports the option
52 dnl '-Werror=implicit-function-declaration'.
53 saved_ac_compile="$ac_compile"
54 ac_compile="$ac_compile -Werror=implicit-function-declaration"
55 dnl Use _AC_COMPILE_IFELSE instead of AC_COMPILE_IFELSE, to avoid a
56 dnl warning "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
57 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
58 [gl_cv_compiler_check_decl_option='-Werror=implicit-function-declaration'],
59 [gl_cv_compiler_check_decl_option=none])
60 ac_compile="$saved_ac_compile"
62 gl_cv_compiler_check_decl_option=none
65 if test "x$gl_cv_compiler_check_decl_option" != xnone; then
66 ac_compile_for_check_decl="$ac_compile $gl_cv_compiler_check_decl_option"
68 ac_compile_for_check_decl="$ac_compile"
71 dnl Redefine _AC_CHECK_DECL_BODY so that it references ac_compile_for_check_decl
72 dnl instead of ac_compile. If, for whatever reason, the override of AC_PROG_CC
73 dnl in zzgnulib.m4 is inactive, use the original ac_compile.
74 m4_define([_AC_CHECK_DECL_BODY],
75 [ ac_saved_ac_compile="$ac_compile"
76 if test -n "$ac_compile_for_check_decl"; then
77 ac_compile="$ac_compile_for_check_decl"
79 m4_defn([_AC_CHECK_DECL_BODY])[ ac_compile="$ac_saved_ac_compile"
84 # Witness macro that this file has been included. Needed to force
85 # Automake to include this file prior to all other gnulib .m4 files.
86 AC_DEFUN([gl_00GNULIB])