]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
AC_CHECK_DECL now ignores future Darwin functions
authorBruno Haible <bruno@clisp.org>
Sat, 24 May 2025 10:22:28 +0000 (12:22 +0200)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 26 May 2025 17:55:19 +0000 (10:55 -0700)
* lib/autoconf/general.m4 (_AC_UNDECLARED_BUILTIN):
Use shorter diagnostic, to be consistent with other changes.
(_AC_FUTURE_DARWIN): New macro.
(AC_CHECK_DECL): Require per-language _AC_FUTURE_DARWIN.
Use $ac_c_future_darwin_options alongside with
$ac_c_undeclared_builtin_options.
* NEWS: Mention the fix.
Co-authored-by: Paul Eggert <eggert@cs.ucla.edu>
NEWS
lib/autoconf/general.m4

diff --git a/NEWS b/NEWS
index 1e4e513ec6b6aa7044090b8c01d6d80e7fffe4c6..8c323887f5a2f801e947cebf96204bfaba722e13 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,9 @@ GNU Autoconf NEWS - User visible changes.
 
 ** Notable bug fixes
 
+*** AC_CHECK_DECL and AC_CHECK_DECLS will, on macOS, now report "no" for
+  functions that are declared as existing in future macOS versions only.
+
 *** AC_DEFINE_UNQUOTED no longer mishandles double-quotes inside $(...)
   and ${...}.
 
index 7eae5bd23110fb66fcacf8b6fd6b4ef8e3e16ac7..dccddbe14878feb56453e5e791f833c2799d053f 100644 (file)
@@ -3105,7 +3105,7 @@ AC_DEFUN([AC_CHECK_FILES],
 # used by AC_CHECK_DECL, report failure.
 AC_DEFUN([_AC_UNDECLARED_BUILTIN],
 [AC_CACHE_CHECK(
-  [for $[]_AC_CC options needed to detect all undeclared functions],
+  [for $[]_AC_CC options to detect undeclared functions],
   [ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options],
   [ac_save_CFLAGS=$CFLAGS
    ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options='cannot detect'
@@ -3145,6 +3145,39 @@ extern void ac_decl (int, char *);
       [ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options=$ac_cv_[]_AC_LANG_ABBREV[]_undeclared_builtin_options])
 ])
 
+# _AC_FUTURE_DARWIN
+# -----------------
+# Set ac_[]_AC_LANG_ABBREV[]_future_darwin_options to any options needed
+# to make the compiler issue a hard error, not a warning, when a function
+# is used that is declared in the .h files but that is introduced in a
+# version *after* the current minimum OS version.
+# These options should not cause any other unrelated warnings to become
+# errors.
+AC_DEFUN([_AC_FUTURE_DARWIN],
+[AC_CACHE_CHECK(
+  [for $[]_AC_CC options to ignore future-version functions],
+  [ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options],
+  [dnl Test whether the compiler supports the option
+   dnl '-Werror=unguarded-availability-new'.
+   ac_compile_saved="$ac_compile"
+   ac_compile="$ac_compile -Werror=unguarded-availability-new"
+   AC_COMPILE_IFELSE(
+     [AC_LANG_PROGRAM(
+       [[#if ! (defined __APPLE__ && defined __MACH__)
+          #error "-Werror=unguarded-availability-new not needed here"
+         #endif
+       ]],
+       [[]])],
+     [ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options='-Werror=unguarded-availability-new'],
+     [ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options='none needed'])
+   ac_compile="$ac_compile_saved"
+  ])
+ AS_CASE([$ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options],
+   ['none needed'],
+     [ac_[]_AC_LANG_ABBREV[]_future_darwin_options=''],
+     [ac_[]_AC_LANG_ABBREV[]_future_darwin_options=$ac_cv_[]_AC_LANG_ABBREV[]_future_darwin_options])
+])
+
 # _AC_CHECK_DECL_BODY
 # -------------------
 # Shell function body for AC_CHECK_DECL.
@@ -3195,10 +3228,16 @@ dnl Initialize each $ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options once.
 [AC_DEFUN([_AC_UNDECLARED_BUILTIN_]_AC_LANG_ABBREV,
           [_AC_UNDECLARED_BUILTIN])]dnl
 [AC_REQUIRE([_AC_UNDECLARED_BUILTIN_]_AC_LANG_ABBREV)]dnl
+dnl Initialize each $ac_[]_AC_LANG_ABBREV[]_future_darwin_options once.
+[AC_DEFUN([_AC_FUTURE_DARWIN_]_AC_LANG_ABBREV,
+         [_AC_FUTURE_DARWIN])]dnl
+[AC_REQUIRE([_AC_FUTURE_DARWIN_]_AC_LANG_ABBREV)]dnl
 [AS_VAR_PUSHDEF([ac_Symbol], [ac_cv_have_decl_$1])]dnl
 [ac_fn_check_decl ]dnl
 ["$LINENO" "$1" "ac_Symbol" "AS_ESCAPE([AC_INCLUDES_DEFAULT([$4])], [""])" ]dnl
-["$ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options" "_AC_LANG_PREFIX[]FLAGS"]
+["$ac_[]_AC_LANG_ABBREV[]_undeclared_builtin_options]dnl
+[$ac_[]_AC_LANG_ABBREV[]_future_darwin_options" ]dnl
+["_AC_LANG_PREFIX[]FLAGS"]
 [AS_VAR_IF([ac_Symbol], [yes], [$2], [$3])]dnl
 [AS_VAR_POPDEF([ac_Symbol])]dnl
 )# AC_CHECK_DECL