Paul Eggert wrote:
> diff --git a/m4/reallocarray.m4 b/m4/reallocarray.m4
> index 9407a7fe63..cc2ef2ccaa 100644
> --- a/m4/reallocarray.m4
> +++ b/m4/reallocarray.m4
> ...
> @@ -13,14 +13,19 @@ AC_DEFUN([gl_FUNC_REALLOCARRAY],
>
> AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
> AC_REQUIRE([gl_CHECK_MALLOC_PTRDIFF])
> + AC_REQUIRE([gl_FUNC_REALLOC_0_NONNULL])
> + REPLACE_REALLOCARRAY=$REPLACE_REALLOC_FOR_REALLOC_POSIX
> gl_CHECK_FUNCS_ANDROID([reallocarray], [[#include <stdlib.h>]])
> if test "$ac_cv_func_reallocarray" = no; then
> HAVE_REALLOCARRAY=0
> case "$gl_cv_onwards_func_reallocarray" in
> future*) REPLACE_REALLOCARRAY=1 ;;
> esac
> - elif test "$gl_cv_malloc_ptrdiff" = no; then
> - REPLACE_REALLOCARRAY=1
> + else
> + case $gl_cv_func_realloc_0_nonnull in
> + *yes) ;;
> + *) REPLACE_REALLOCARRAY=1 ;;
> + esac
> fi
> ])
The CI reports that this change causes a compilation error in C++ mode on
CentOS 7:
gcc -std=gnu11 -Wno-error -g -O2 -o test-stdio test-stdio.o libtests.a
../gllib/libgnu.a libtests.a ../gllib/libgnu.a libtests.a -lbacktrace -lm -lm
-lm -lm -lm -lm -lm -lm -lm -lm -lm
depbase=`echo test-stdlib-c++.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\
g++ -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -I. -I../../gltests -I..
-DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I..
-I../../gltests/.. -I../gllib -I../../gltests/../gllib -Wall
-DCONTINUE_AFTER_ASSERT -Wno-error -g -O2 -MT test-stdlib-c++.o -MD -MP -MF
$depbase.Tpo -c -o test-stdlib-c++.o ../../gltests/test-stdlib-c++.cc &&\
mv -f $depbase.Tpo $depbase.Po
In file included from /usr/include/sys/types.h:219:0,
from ../gllib/sys/types.h:46,
from /usr/include/stdlib.h:314,
from ../gllib/stdlib.h:51,
from ../../gltests/test-stdlib-c++.cc:22:
../gllib/stdlib.h:2134:1: error: 'reallocarray' was not declared in this scope
_GL_CXXALIASWARN (reallocarray);
^
../gllib/stdlib.h:2134:1: note: suggested alternative:
../gllib/stdlib.h:2122:1: note: 'gnulib::reallocarray'
_GL_CXXALIAS_RPL (reallocarray, void *,
^
In file included from ../../gltests/test-stdlib-c++.cc:22:0:
../gllib/stdlib.h:2134:32: error: invalid type in declaration before ';' token
_GL_CXXALIASWARN (reallocarray);
^
make[4]: *** [test-stdlib-c++.o] Error 1
In config.status I find that
- HAVE_REALLOCARRAY is 0,
- REPLACE_REALLOCARRAY is 2.
Two things are wrong with that:
* REPLACE_REALLOCARRAY should never be 2, only 1, because
- In the module description we have
test $REPLACE_REALLOCARRAY = 1
not
test $REPLACE_REALLOCARRAY != 0
- There is no inline definition for reallocarray in stdlib.in.h.
* Generally, we avoid to set REPLACE_FOO to 1 if HAVE_FOO is 0.
We do it only when necessary on specific platforms (Android or macOS).
As we can see in this case, in this situation things won't work in C++ mode;
therefore it's better to not need it unless necessary.
Additionally, if the intention was to not test $gl_cv_malloc_ptrdiff any more,
here, the AC_REQUIRE([gl_CHECK_MALLOC_PTRDIFF]) could have been removed.
This patch fixes it.
2024-11-06 Bruno Haible <[email protected]>
reallocarray: Fix compilation error in C++ mode (regr. 2024-11-04).
* m4/reallocarray.m4 (gl_FUNC_REALLOCARRAY): Don't use
REPLACE_REALLOC_FOR_REALLOC_POSIX here. Use gl_cv_malloc_ptrdiff
instead.
diff --git a/m4/reallocarray.m4 b/m4/reallocarray.m4
index cc2ef2ccaa..c115dfbe45 100644
--- a/m4/reallocarray.m4
+++ b/m4/reallocarray.m4
@@ -1,5 +1,5 @@
# reallocarray.m4
-# serial 6
+# serial 7
dnl Copyright (C) 2017-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -14,7 +14,6 @@ AC_DEFUN([gl_FUNC_REALLOCARRAY]
AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_REQUIRE([gl_CHECK_MALLOC_PTRDIFF])
AC_REQUIRE([gl_FUNC_REALLOC_0_NONNULL])
- REPLACE_REALLOCARRAY=$REPLACE_REALLOC_FOR_REALLOC_POSIX
gl_CHECK_FUNCS_ANDROID([reallocarray], [[#include <stdlib.h>]])
if test "$ac_cv_func_reallocarray" = no; then
HAVE_REALLOCARRAY=0
@@ -22,7 +21,10 @@ AC_DEFUN([gl_FUNC_REALLOCARRAY]
future*) REPLACE_REALLOCARRAY=1 ;;
esac
else
- case $gl_cv_func_realloc_0_nonnull in
+ if test "$gl_cv_malloc_ptrdiff" = no; then
+ REPLACE_REALLOCARRAY=1
+ fi
+ case "$gl_cv_func_realloc_0_nonnull" in
*yes) ;;
*) REPLACE_REALLOCARRAY=1 ;;
esac