summaryrefslogtreecommitdiff
path: root/gnulib-m4/gnulib-common.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gnulib-m4/gnulib-common.m4')
-rw-r--r--gnulib-m4/gnulib-common.m4213
1 files changed, 137 insertions, 76 deletions
diff --git a/gnulib-m4/gnulib-common.m4 b/gnulib-m4/gnulib-common.m4
index 1fec5c5c..26eef771 100644
--- a/gnulib-m4/gnulib-common.m4
+++ b/gnulib-m4/gnulib-common.m4
@@ -1,9 +1,10 @@
# gnulib-common.m4
-# serial 105
-dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
+# serial 115
+dnl Copyright (C) 2007-2026 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
+dnl This file is offered as-is, without any warranty.
AC_PREREQ([2.62])
@@ -20,6 +21,20 @@ AC_DEFUN([gl_COMMON_BODY], [
[/* Witness that <config.h> has been included. */
#define _GL_CONFIG_H_INCLUDED 1
])
+ dnl Avoid warnings from gcc -Wtrailing-whitespace.
+ dnl This is a temporary workaround until Autoconf fixes it.
+ dnl Test case:
+ dnl empty1=; empty2=; AC_DEFINE_UNQUOTED([FOO], [$empty1$empty2], [...])
+ dnl should produce "#define FOO /**/", not "#define FOO ".
+ AH_TOP([#if defined __GNUC__ && __GNUC__ >= 15 && !defined __clang__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wtrailing-whitespace"
+#endif
+])
+ AH_BOTTOM([#if defined __GNUC__ && __GNUC__ >= 15 && !defined __clang__
+# pragma GCC diagnostic pop
+#endif
+])
AH_VERBATIM([_GL_GNUC_PREREQ],
[/* True if the compiler says it groks GNU C version MAJOR.MINOR.
Except that
@@ -42,33 +57,25 @@ AC_DEFUN([gl_COMMON_BODY], [
#endif
])
AH_VERBATIM([_Noreturn],
-[/* The _Noreturn keyword of C11. */
+[/* The _Noreturn keyword of C11.
+ Do not use [[noreturn]], because with it the syntax
+ extern _Noreturn void func (...);
+ would not be valid; such a declaration would be valid only with 'extern'
+ and '_Noreturn' swapped, or without the 'extern' keyword. However, some
+ AIX system header files and several gnulib header files use precisely
+ this syntax with 'extern'. So even though C23 deprecates _Noreturn,
+ it is currently more portable to prefer it to [[noreturn]].
+
+ Also, do not try to work around LLVM bug 59792 (clang 15 or earlier).
+ This rare bug can be worked around by compiling with 'clang -D_Noreturn=',
+ though the workaround may generate many false-alarm warnings. */
#ifndef _Noreturn
-# if (defined __cplusplus \
- && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
- || (defined _MSC_VER && 1900 <= _MSC_VER)) \
- && 0)
- /* [[noreturn]] is not practically usable, because with it the syntax
- extern _Noreturn void func (...);
- would not be valid; such a declaration would only be valid with 'extern'
- and '_Noreturn' swapped, or without the 'extern' keyword. However, some
- AIX system header files and several gnulib header files use precisely
- this syntax with 'extern'. */
-# define _Noreturn [[noreturn]]
-# elif (defined __clang__ && __clang_major__ < 16 \
- && defined _GL_WORK_AROUND_LLVM_BUG_59792)
- /* Compile with -D_GL_WORK_AROUND_LLVM_BUG_59792 to work around
- that rare LLVM bug, though you may get many false-alarm warnings. */
-# define _Noreturn
-# elif ((!defined __cplusplus || defined __clang__) \
- && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
- || (!defined __STRICT_ANSI__ \
- && (_GL_GNUC_PREREQ (4, 7) \
- || (defined __apple_build_version__ \
- ? 6000000 <= __apple_build_version__ \
- : 3 < __clang_major__ + (5 <= __clang_minor__))))))
+# if ((!defined __cplusplus || defined __clang__) \
+ && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0)))
/* _Noreturn works as-is. */
# elif _GL_GNUC_PREREQ (2, 8) || defined __clang__ || 0x5110 <= __SUNPRO_C
+ /* Prefer __attribute__ ((__noreturn__)) to plain _Noreturn even if the
+ latter works, as 'gcc -std=gnu99 -Wpedantic' warns about _Noreturn. */
# define _Noreturn __attribute__ ((__noreturn__))
# elif 1200 <= (defined _MSC_VER ? _MSC_VER : 0)
# define _Noreturn __declspec (noreturn)
@@ -102,6 +109,9 @@ AC_DEFUN([gl_COMMON_BODY], [
# define _GL_HAS_ATTRIBUTE(attr) __has_attribute (__##attr##__)
# else
# define _GL_HAS_ATTRIBUTE(attr) _GL_ATTR_##attr
+/* The following lines list the first GCC version that supports the attribute.
+ Although the lines are not used in GCC 5 and later (as GCC 5 introduced
+ __has_attribute support), list GCC versions 5+ anyway for completeness. */
# define _GL_ATTR_alloc_size _GL_GNUC_PREREQ (4, 3)
# define _GL_ATTR_always_inline _GL_GNUC_PREREQ (3, 2)
# define _GL_ATTR_artificial _GL_GNUC_PREREQ (4, 3)
@@ -122,14 +132,15 @@ AC_DEFUN([gl_COMMON_BODY], [
# endif
# define _GL_ATTR_noinline _GL_GNUC_PREREQ (3, 1)
# define _GL_ATTR_nonnull _GL_GNUC_PREREQ (3, 3)
+# define _GL_ATTR_nonnull_if_nonzero _GL_GNUC_PREREQ (15, 1)
# define _GL_ATTR_nonstring _GL_GNUC_PREREQ (8, 0)
# define _GL_ATTR_nothrow _GL_GNUC_PREREQ (3, 3)
# define _GL_ATTR_packed _GL_GNUC_PREREQ (2, 7)
# define _GL_ATTR_pure _GL_GNUC_PREREQ (2, 96)
-# define _GL_ATTR_reproducible 0 /* not yet supported, as of GCC 14 */
+# define _GL_ATTR_reproducible _GL_GNUC_PREREQ (15, 1)
# define _GL_ATTR_returns_nonnull _GL_GNUC_PREREQ (4, 9)
# define _GL_ATTR_sentinel _GL_GNUC_PREREQ (4, 0)
-# define _GL_ATTR_unsequenced 0 /* not yet supported, as of GCC 14 */
+# define _GL_ATTR_unsequenced _GL_GNUC_PREREQ (15, 1)
# define _GL_ATTR_unused _GL_GNUC_PREREQ (2, 7)
# define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
# endif
@@ -157,7 +168,7 @@ AC_DEFUN([gl_COMMON_BODY], [
======================================================================
This gives a syntax error
- in C mode with gcc
- <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108796>, and
+ <https://gcc.gnu.org/PR108796>, and
- in C++ mode with clang++ version < 16, and
- in C++ mode, inside extern "C" {}, still in newer clang++ versions
<https://github.com/llvm/llvm-project/issues/101990>.
@@ -403,22 +414,25 @@ AC_DEFUN([gl_COMMON_BODY], [
#endif
/* _GL_ATTRIBUTE_CONST declares:
- It is OK for a compiler to move calls to the function and to omit
- calls to the function if another call has the same arguments or the
- result is not used.
- This attribute is safe for a function that neither depends on
- nor affects state, and always returns exactly once -
+ It is OK for a compiler to move a call, or omit a duplicate call
+ and reuse a cached return value, even if the state changes between calls.
+ It is also OK to omit a call if the result is not used.
+ This attribute is safe if the function does not change observable state,
+ returns a value determined solely by its arguments' values
+ without examining state, and always returns exactly once -
e.g., does not raise an exception, call longjmp, or loop forever.
(This attribute is stricter than _GL_ATTRIBUTE_PURE because the
- function cannot observe state. It is stricter than
- _GL_ATTRIBUTE_UNSEQUENCED because the function must return exactly
- once and cannot depend on state addressed by its arguments.) */
+ function cannot observe state. Unlike _GL_ATTRIBUTE_UNSEQUENCED
+ the function must return exactly once and cannot access state
+ addressed by its pointer arguments or that happens to have the same
+ value for all calls to the function, but the function is allowed to
+ return a pointer to storage that can be modified later. */
/* Applies to: functions. */
#ifndef _GL_ATTRIBUTE_CONST
# if _GL_HAS_ATTRIBUTE (const)
# define _GL_ATTRIBUTE_CONST __attribute__ ((__const__))
# else
-# define _GL_ATTRIBUTE_CONST _GL_ATTRIBUTE_UNSEQUENCED
+# define _GL_ATTRIBUTE_CONST
# endif
#endif
@@ -440,7 +454,7 @@ AC_DEFUN([gl_COMMON_BODY], [
yet. */
#ifndef _GL_ATTRIBUTE_DEALLOC_FREE
# if defined __cplusplus && defined __GNUC__ && !defined __clang__
-/* Work around GCC bug <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108231> */
+/* Work around GCC bug <https://gcc.gnu.org/PR108231> */
# define _GL_ATTRIBUTE_DEALLOC_FREE \
_GL_ATTRIBUTE_DEALLOC ((void (*) (void *)) free, 1)
# else
@@ -579,7 +593,9 @@ AC_DEFUN([gl_COMMON_BODY], [
/* _GL_ATTRIBUTE_MAYBE_UNUSED declares that it is not a programming mistake if
the entity is not used. The compiler should not warn if the entity is not
- used. */
+ used. However, 'int _GL_UNNAMED (i)' is preferable to
+ '_GL_ATTRIBUTE_MAYBE_UNUSED int i' when parameter I is unused
+ regardless of preprocessor macro settings. */
/* Applies to:
- function, variable,
- struct, union, struct/union member,
@@ -666,6 +682,17 @@ AC_DEFUN([gl_COMMON_BODY], [
# endif
#endif
+/* _GL_ATTRIBUTE_NONNULL_IF_NONZERO (NP, NI) declares that the argument NP
+ (a pointer) must not be NULL if the argument NI (an integer) is != 0. */
+/* Applies to: functions. */
+#ifndef _GL_ATTRIBUTE_NONNULL_IF_NONZERO
+# if _GL_HAS_ATTRIBUTE (nonnull_if_nonzero)
+# define _GL_ATTRIBUTE_NONNULL_IF_NONZERO(np, ni) __attribute__ ((__nonnull_if_nonzero__ (np, ni)))
+# else
+# define _GL_ATTRIBUTE_NONNULL_IF_NONZERO(np, ni)
+# endif
+#endif
+
/* _GL_ATTRIBUTE_NONSTRING declares that the contents of a character array is
not meant to be NUL-terminated. */
/* Applies to: struct/union members and variables that are arrays of element
@@ -722,35 +749,38 @@ AC_DEFUN([gl_COMMON_BODY], [
#endif
/* _GL_ATTRIBUTE_PURE declares:
- It is OK for a compiler to move calls to the function and to omit
- calls to the function if another call has the same arguments or the
- result is not used, and if observable state is the same.
- This attribute is safe for a function that does not affect observable state
- and always returns exactly once.
+ It is OK for a compiler to move a call, or omit a duplicate call
+ and reuse a cached return value, if observable state is the same.
+ It is also OK to omit a call if the return value is not used.
+ This attribute is safe if the function does not change observable state,
+ returns a value determined solely by its arguments's values
+ together with observable state, and always returns exactly once.
(This attribute is looser than _GL_ATTRIBUTE_CONST because the function
- can depend on observable state. It is stricter than
- _GL_ATTRIBUTE_REPRODUCIBLE because the function must return exactly
- once and cannot affect state addressed by its arguments.) */
+ can depend on observable state.
+ Unlike _GL_ATTRIBUTE_REPRODUCIBLE the function must return exactly
+ once and cannot change state addressed by its arguments, but the
+ function can return a pointer to storage whose contents change later.) */
/* Applies to: functions. */
#ifndef _GL_ATTRIBUTE_PURE
# if _GL_HAS_ATTRIBUTE (pure)
# define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
-# define _GL_ATTRIBUTE_PURE _GL_ATTRIBUTE_REPRODUCIBLE
+# define _GL_ATTRIBUTE_PURE
# endif
#endif
/* _GL_ATTRIBUTE_REPRODUCIBLE declares:
- It is OK for a compiler to move calls to the function and to omit duplicate
- calls to the function with the same arguments, so long as the state
- addressed by its arguments is the same and is updated in time for
- the rest of the program.
- This attribute is safe for a function that is effectless and idempotent; see
- ISO C 23 § 6.7.12.7 for a definition of these terms.
+ It is OK for a compiler to move a call, or omit a duplicate call
+ and reuse a cached value returned either directly or indirectly via
+ a pointer, if other observable state is the same;
+ however, pointer arguments cannot alias.
+ This attribute is safe for a function that is effectless and idempotent;
+ see ISO C 23 § 6.7.13.8 for a definition of these terms.
(This attribute is looser than _GL_ATTRIBUTE_UNSEQUENCED because
- the function need not be stateless and idempotent. It is looser
- than _GL_ATTRIBUTE_PURE because the function need not return
- exactly once and can affect state addressed by its arguments.)
+ the function need not be stateless or independent.
+ Unlike _GL_ATTRIBUTE_PURE the function need not return exactly once
+ and can change state addressed by its pointer arguments, but the
+ function cannot return a pointer to storage whose contents change later.)
See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
<https://stackoverflow.com/questions/76847905/>. */
/* Applies to: functions, pointer to functions, function types. */
@@ -792,16 +822,20 @@ AC_DEFUN([gl_COMMON_BODY], [
#endif
/* _GL_ATTRIBUTE_UNSEQUENCED declares:
- It is OK for a compiler to move calls to the function and to omit duplicate
- calls to the function with the same arguments, so long as the state
- addressed by its arguments is the same.
+ It is OK for a compiler to move a call, or omit a duplicate call
+ and reuse a cached value returned either directly or indirectly via
+ a pointer, if the state addressed by its pointer arguments is the same;
+ however, pointer arguments cannot alias.
This attribute is safe for a function that is effectless, idempotent,
- stateless, and independent; see ISO C 23 § 6.7.12.7 for a definition of
+ stateless, and independent; see ISO C 23 § 6.7.13.8 for a definition of
these terms.
(This attribute is stricter than _GL_ATTRIBUTE_REPRODUCIBLE because
- the function must be stateless and independent. It is looser than
- _GL_ATTRIBUTE_CONST because the function need not return exactly
- once and can depend on state addressed by its arguments.)
+ the function must be stateless and independent. Unlike
+ _GL_ATTRIBUTE_CONST the function need not return exactly once, and
+ can depend on state accessed via its pointer arguments or that
+ happens to have the same value for all calls to the function, but
+ the function cannot return a pointer to storage whose contents
+ change later.)
See also <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2956.htm> and
<https://stackoverflow.com/questions/76847905/>. */
/* Applies to: functions, pointer to functions, function types. */
@@ -843,6 +877,21 @@ AC_DEFUN([gl_COMMON_BODY], [
# endif
#endif
+/* _GL_UNNAMED (ID) is the "name" of an unnamed function parameter.
+ Each of the function's unnamed parameters should have a unique "name".
+ The "name" cannot be used. This ports both to C17 and earlier, which
+ lack unnamed parameters, and to C++ and later C, which have them. */
+/* Applies to:
+ - function parameters. */
+#ifndef _GL_UNNAMED
+# if ((defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 202311 \
+ && !defined __cplusplus)
+# define _GL_UNNAMED(id) unnamed_##id _GL_ATTRIBUTE_UNUSED
+# else
+# define _GL_UNNAMED(id)
+# endif
+#endif
+
/* The following attributes enable detection of multithread-safety problems
and resource leaks at compile-time, by clang ≥ 15, when the warning option
-Wthread-safety is enabled. For usage, see
@@ -851,7 +900,7 @@ AC_DEFUN([gl_COMMON_BODY], [
# if __clang_major__ >= 15
# define _GL_ATTRIBUTE_CAPABILITY_TYPE(concept) \
__attribute__ ((__capability__ (concept)))
-#else
+# else
# define _GL_ATTRIBUTE_CAPABILITY_TYPE(concept)
# endif
#endif
@@ -921,8 +970,8 @@ AC_DEFUN([gl_COMMON_BODY], [
-1 if n1 < n2
The naïve code (n1 > n2 ? 1 : n1 < n2 ? -1 : 0) produces a conditional
jump with nearly all GCC versions up to GCC 10.
- This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional with many
- GCC versions up to GCC 9.
+ This variant (n1 < n2 ? -1 : n1 > n2) produces a conditional jump with
+ many GCC versions up to GCC 9.
The better code (n1 > n2) - (n1 < n2) from Hacker's Delight § 2-9
avoids conditional jumps in all GCC versions >= 3.4. */
#define _GL_CMP(n1, n2) (((n1) > (n2)) - ((n1) < (n2)))
@@ -1299,7 +1348,7 @@ AC_DEFUN([gl_CC_ALLOW_WARNINGS],
AC_REQUIRE([AC_PROG_CC])
AC_CACHE_CHECK([for C compiler option to allow warnings],
[gl_cv_cc_wallow],
- [rm -f conftest*
+ [rm -fr conftest*
echo 'int dummy;' > conftest.c
AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 2>conftest1.err]) >/dev/null
AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -Wno-error -c conftest.c 2>conftest2.err]) >/dev/null
@@ -1312,7 +1361,7 @@ AC_DEFUN([gl_CC_ALLOW_WARNINGS],
else
gl_cv_cc_wallow=none
fi
- rm -f conftest*
+ rm -fr conftest*
])
case "$gl_cv_cc_wallow" in
none) GL_CFLAG_ALLOW_WARNINGS='' ;;
@@ -1330,7 +1379,7 @@ AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
if test -n "$CXX" && test "$CXX" != no; then
AC_CACHE_CHECK([for C++ compiler option to allow warnings],
[gl_cv_cxx_wallow],
- [rm -f conftest*
+ [rm -fr conftest*
echo 'int dummy;' > conftest.cc
AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 2>conftest1.err]) >/dev/null
AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -Wno-error -c conftest.cc 2>conftest2.err]) >/dev/null
@@ -1343,7 +1392,7 @@ AC_DEFUN([gl_CXX_ALLOW_WARNINGS],
else
gl_cv_cxx_wallow=none
fi
- rm -f conftest*
+ rm -fr conftest*
])
case "$gl_cv_cxx_wallow" in
none) GL_CXXFLAG_ALLOW_WARNINGS='' ;;
@@ -1380,7 +1429,7 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
dnl -Wno-type-limits >= 4.3 >= 3.9
dnl -Wno-undef >= 3 >= 3.9
dnl -Wno-unsuffixed-float-constants >= 4.5
- dnl -Wno-unused-const-variable >= 4.4 >= 3.9
+ dnl -Wno-unused-const-variable >= 6.1 >= 3.9
dnl -Wno-unused-function >= 3 >= 3.9
dnl -Wno-unused-parameter >= 3 >= 3.9
dnl
@@ -1410,7 +1459,7 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
-Wno-sign-conversion
-Wno-type-limits
#endif
- #if (__GNUC__ + (__GNUC_MINOR__ >= 4) > 4 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+ #if (__GNUC__ + (__GNUC_MINOR__ >= 1) > 6 && !defined __clang__) || (__clang_major__ + (__clang_minor__ >= 9) > 3)
-Wno-unused-const-variable
#endif
#if (__GNUC__ + (__GNUC_MINOR__ >= 5) > 4 && !defined __clang__)
@@ -1537,13 +1586,25 @@ AC_DEFUN([gl_CHECK_FUNCS_CASE_FOR_MACOS],
if test $[ac_cv_func_][$1] = yes; then
[gl_cv_onwards_func_][$1]=yes
else
+ dnl This is a bit complicated, because here we need the behaviour
+ dnl of AC_CHECK_DECL before the
+ dnl commit e1bbc9b93cdff61d70719c224b37970e065008bb (2025-05-26).
+ [ac_cv_have_decl_][$1][_saved]="$[ac_cv_have_decl_][$1]"
unset [ac_cv_have_decl_][$1]
+ ac_c_future_darwin_options_saved="$ac_c_future_darwin_options"
+ ac_cxx_future_darwin_options_saved="$ac_cxx_future_darwin_options"
+ ac_c_future_darwin_options=
+ ac_cxx_future_darwin_options=
AC_CHECK_DECL([$1], , , [$2])
+ ac_c_future_darwin_options="$ac_c_future_darwin_options_saved"
+ ac_cxx_future_darwin_options="$ac_cxx_future_darwin_options_saved"
if test $[ac_cv_have_decl_][$1] = yes; then
[gl_cv_onwards_func_][$1]='future OS version'
else
[gl_cv_onwards_func_][$1]=no
fi
+ [ac_cv_have_decl_][$1]="$[ac_cv_have_decl_][$1][_saved]"
+ unset [ac_cv_have_decl_][$1][_saved]
fi
else
AC_CHECK_FUNC([$1])
@@ -1596,7 +1657,7 @@ dnl
dnl This macro sets two variables:
dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
dnl - ac_cv_func_<func> to yes / no / no
-dnl The first variable allows to distinguish all three cases.
+dnl The first variable allows distinguishing all three cases.
dnl The second variable is set, so that an invocation
dnl gl_CHECK_FUNCS_ANDROID([func], [[#include <foo.h>]])
dnl can be used as a drop-in replacement for
@@ -1649,7 +1710,7 @@ dnl
dnl This macro sets two variables:
dnl - gl_cv_onwards_func_<func> to yes / no / "future OS version"
dnl - ac_cv_func_<func> to yes / no / no
-dnl The first variable allows to distinguish all three cases.
+dnl The first variable allows distinguishing all three cases.
dnl The second variable is set, so that an invocation
dnl gl_CHECK_FUNCS_MACOS([func], [[#include <foo.h>]])
dnl can be used as a drop-in replacement for