On 2025-05-24 04:37, Bruno Haible via Bug reports for autoconf wrote:
Here's a proposed fix for the issue along these lines.

Thanks. It'd be nicer if AC_CHECK_DECL didn't require AC_CANONICAL_HOST. We can do that by checking inside the C program rather than using AC_CANONICAL_HOST.

Also, shouldn't we simply test for the option in question rather than first checking for Clang? GCC might eventually add it. This way, we don't need to test for Clang.

So, how about the attached patch instead?
From 2684ac44095bee4e3943aa666fc20dad85ad028d Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 24 May 2025 12:22:28 +0200
Subject: [PATCH] AC_CHECK_DECL now ignores future Darwin functions

* 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.
---
 NEWS                    |  3 +++
 lib/autoconf/general.m4 | 43 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 1e4e513e..8c323887 100644
--- 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 ${...}.
 
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 7eae5bd2..dccddbe1 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -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
-- 
2.48.1

Reply via email to