3 dnl Copyright (C) 2010-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 # gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES)
9 # ---------------------------------------
10 # If the module 'posixcheck' is in use:
12 # For each whitespace-separated element in the list of NAMES, define
13 # HAVE_RAW_DECL_name if the function has a declaration among INCLUDES
14 # even after being undefined as a macro.
16 # See warn-on-use.h for some hints on how to poison function names, as
17 # well as ideas on poisoning global variables and macros. NAMES may
18 # include global variables, but remember that only functions work with
19 # _GL_WARN_ON_USE. Typically, INCLUDES only needs to list a single
20 # header, but if the replacement header pulls in other headers because
21 # some systems declare functions in the wrong header, then INCLUDES
24 # It is generally safe to assume declarations for functions declared
25 # in the intersection of C89 and C11 (such as printf) without
26 # needing gl_WARN_ON_USE_PREPARE.
27 AC_DEFUN([gl_WARN_ON_USE_PREPARE],
29 m4_ifdef([gl_POSIXCHECK],
30 [m4_foreach_w([gl_decl], [$2],
31 [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])),
32 [Define to 1 if ]m4_defn([gl_decl])[ is declared even after
33 undefining macros.])])dnl
34 for gl_func in m4_flatten([$2]); do
35 AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl
36 dnl As a workaround to implicit built-in function declarations in
37 dnl clang (e.g. strndup), reference ac_compile_for_check_decl instead
38 dnl of ac_compile. If, for whatever reason, the override of AC_PROG_CC
39 dnl in zzgnulib.m4 is inactive, use the original ac_compile.
40 ac_saved_ac_compile="$ac_compile"
41 if test -n "$ac_compile_for_check_decl"; then
42 ac_compile="$ac_compile_for_check_decl"
44 AC_CACHE_CHECK([whether $gl_func is declared without a macro],
46 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1],
49 [AS_VAR_SET([gl_Symbol], [yes])], [AS_VAR_SET([gl_Symbol], [no])])])
50 ac_compile="$ac_saved_ac_compile"
51 AS_VAR_IF([gl_Symbol], [yes],
52 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
53 dnl Shortcut for an AC_CHECK_DECL invocation that may come later:
54 dnl If the raw declaration exists with the given includes, then
55 dnl AC_CHECK_DECL with its many includes would see it as well.
56 dnl So, set a cache variable to allow skipping any later
57 dnl AC_CHECK_DECL invocation for $gl_func.
58 eval "ac_cv_have_decl_$gl_func=yes"
60 AS_VAR_POPDEF([gl_Symbol])dnl