A testdir built with ./gnulib-tool --create-testdir --dir=../testdir1 --single-configure --with-c++-tests `./posix-modules` does not compile on Solaris 10 with CC="cc -O" and CXX="CC -O":
gmake[4]: Entering directory '/home/haible/testdir1/build-sparc-64-cc/gltests' source='../../gltests/test-math-c++.cc' object='test-math-c++.o' libtool=no \ DEPDIR=.deps depmode=none /bin/bash ../../build-aux/depcomp \ CC -xarch=generic64 -O -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/home/haible/prefix-sparc64/include -D_REENTRANT -c -o test-math-c++.o ../../gltests/test-math-c++.cc "../gllib/math.h", line 2724: Error: The function "isfinite" must have a prototype. "../gllib/math.h", line 2724: Error: The function "isfinite" must have a prototype. "../gllib/math.h", line 2724: Error: The function "isfinite" must have a prototype. "../gllib/math.h", line 2758: Error: The function "isinf" must have a prototype. "../gllib/math.h", line 2758: Error: The function "isinf" must have a prototype. "../gllib/math.h", line 2758: Error: The function "isinf" must have a prototype. "../gllib/math.h", line 2966: Error: The function "signbit" must have a prototype. "../gllib/math.h", line 2966: Error: The function "signbit" must have a prototype. "../gllib/math.h", line 2966: Error: The function "signbit" must have a prototype. 9 Error(s) and 88 Warning(s) detected. gmake[4]: *** [Makefile:9711: test-math-c++.o] Error 9 source='../../gltests/test-pthread-c++.cc' object='test-pthread-c++.o' libtool=no \ DEPDIR=.deps depmode=none /bin/bash ../../build-aux/depcomp \ CC -xarch=generic64 -O -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/home/haible/prefix-sparc64/include -D_REENTRANT -c -o test-pthread-c++.o ../../gltests/test-pthread-c++.cc "../gllib/pthread.h", line 983: Error: Cannot return extern "C" int(*)(unsigned*,const _pthread_attr*,extern "C" void*(*)(void*),void*) from a function that should return int(*)(unsigned*,const _pthread_attr*,void*(*)(void*),void*). "../gllib/pthread.h", line 1237: Error: Cannot return extern "C" int(*)(_once*,extern "C" void(*)()) from a function that should return int(*)(_once*,void(*)()). "../gllib/pthread.h", line 2111: Error: Cannot return extern "C" int(*)(unsigned*,extern "C" void(*)(void*)) from a function that should return int(*)(unsigned*,void(*)(void*)). 3 Error(s) and 48 Warning(s) detected. gmake[4]: *** [Makefile:9711: test-pthread-c++.o] Error 3 source='../../gltests/test-threads-c++.cc' object='test-threads-c++.o' libtool=no \ DEPDIR=.deps depmode=none /bin/bash ../../build-aux/depcomp \ CC -xarch=generic64 -O -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/home/haible/prefix-sparc64/include -D_REENTRANT -c -o test-threads-c++.o ../../gltests/test-threads-c++.cc "../gllib/threads.h", line 953: Error: Cannot return extern "C" void(*)(_once*,extern "C" void(*)()) from a function that should return void(*)(_once*,void(*)()). 4 Error(s) and 81 Warning(s) detected. gmake[4]: *** [Makefile:9711: test-threads-c++.o] Error 4 Regarding the first problem, e.g. isfinite is not declared in C++ mode. We need to provide the gnulib replacement, even though this would not be necessary in packages that don't use C++. The second and third problems are that the compiler distinguishes C function pointers and C++ function pointers, even if they have the same arguments and return types. AFAIK, such a distinction is not necessary in practice: such function pointers are interchangeable. So let's use a cast. On Solaris 11, I also got a compilation error regarding iconv. Apparently the #ifs in the system's <iconv.h> pick a different declaration of iconv() in C++ mode than in C mode, and since our autoconf tests that determine ICONV_CONST run with the C compiler, ... - We need a cast here as well. 2019-12-05 Bruno Haible <[email protected]> Fix compilation errors in C++ mode on Solaris 10 and Solaris 11. * m4/isfinite.m4 (gl_ISFINITE): Require AC_CANONICAL_HOST. On Solaris, set REPLACE_ISFINITE to 1. * m4/isinf.m4 (gl_ISINF): Require AC_CANONICAL_HOST. On Solaris, set REPLACE_ISINF to 1. * m4/signbit.m4 (gl_SIGNBIT): On Solaris, set REPLACE_SIGNBIT to 1. * lib/pthread.in.h (pthread_create, pthread_once, pthread_key_create): Use _GL_CXXALIAS_SYS_CAST instead of _GL_CXXALIAS_SYS. * lib/threads.in.h (call_once): Likewise. * lib/iconv.in.h (iconv): Likewise. diff --git a/lib/iconv.in.h b/lib/iconv.in.h index f244f87..62e6986 100644 --- a/lib/iconv.in.h +++ b/lib/iconv.in.h @@ -87,10 +87,12 @@ _GL_CXXALIAS_RPL (iconv, size_t, @ICONV_CONST@ char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)); # else -_GL_CXXALIAS_SYS (iconv, size_t, - (iconv_t cd, - @ICONV_CONST@ char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft)); +/* Need to cast, because on some versions of Solaris, ICONV_CONST does + not have the right value for C++. */ +_GL_CXXALIAS_SYS_CAST (iconv, size_t, + (iconv_t cd, + @ICONV_CONST@ char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft)); # endif _GL_CXXALIASWARN (iconv); # ifndef ICONV_CONST diff --git a/lib/pthread.in.h b/lib/pthread.in.h index a2c76e4..4ba7e7b 100644 --- a/lib/pthread.in.h +++ b/lib/pthread.in.h @@ -464,9 +464,9 @@ _GL_FUNCDECL_SYS (pthread_create, int, void * (*mainfunc) (void *), void *arg) _GL_ARG_NONNULL ((1, 3))); # endif -_GL_CXXALIAS_SYS (pthread_create, int, - (pthread_t *threadp, const pthread_attr_t *attr, - void * (*mainfunc) (void *), void *arg)); +_GL_CXXALIAS_SYS_CAST (pthread_create, int, + (pthread_t *threadp, const pthread_attr_t *attr, + void * (*mainfunc) (void *), void *arg)); # endif _GL_CXXALIASWARN (pthread_create); #elif defined GNULIB_POSIXCHECK @@ -721,8 +721,9 @@ _GL_FUNCDECL_SYS (pthread_once, int, (pthread_once_t *once_control, void (*initfunction) (void)) _GL_ARG_NONNULL ((1, 2))); # endif -_GL_CXXALIAS_SYS (pthread_once, int, - (pthread_once_t *once_control, void (*initfunction) (void))); +_GL_CXXALIAS_SYS_CAST (pthread_once, int, + (pthread_once_t *once_control, + void (*initfunction) (void))); # endif _GL_CXXALIASWARN (pthread_once); #elif defined GNULIB_POSIXCHECK @@ -1595,8 +1596,8 @@ _GL_FUNCDECL_SYS (pthread_key_create, int, (pthread_key_t *keyp, void (*destructor) (void *)) _GL_ARG_NONNULL ((1))); # endif -_GL_CXXALIAS_SYS (pthread_key_create, int, - (pthread_key_t *keyp, void (*destructor) (void *))); +_GL_CXXALIAS_SYS_CAST (pthread_key_create, int, + (pthread_key_t *keyp, void (*destructor) (void *))); # endif _GL_CXXALIASWARN (pthread_key_create); #elif defined GNULIB_POSIXCHECK diff --git a/lib/threads.in.h b/lib/threads.in.h index 1d28351..3136257 100644 --- a/lib/threads.in.h +++ b/lib/threads.in.h @@ -438,7 +438,7 @@ typedef pthread_once_t once_flag; _GL_FUNCDECL_SYS (call_once, void, (once_flag *, void (*) (void)) _GL_ARG_NONNULL ((1, 2))); # endif -_GL_CXXALIAS_SYS (call_once, void, (once_flag *, void (*) (void))); +_GL_CXXALIAS_SYS_CAST (call_once, void, (once_flag *, void (*) (void))); _GL_CXXALIASWARN (call_once); #elif defined GNULIB_POSIXCHECK # undef call_once diff --git a/m4/isfinite.m4 b/m4/isfinite.m4 index e2a0234..1eb6c0b 100644 --- a/m4/isfinite.m4 +++ b/m4/isfinite.m4 @@ -1,4 +1,4 @@ -# isfinite.m4 serial 16 +# isfinite.m4 serial 17 dnl Copyright (C) 2007-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_ISFINITE], [ AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl Persuade glibc <math.h> to declare isfinite. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_CHECK_DECLS([isfinite], , , [[#include <math.h>]]) @@ -25,8 +26,13 @@ AC_DEFUN([gl_ISFINITE], dnl isfinite(long double) also does not work in this situation. fi fi - if test "$ac_cv_have_decl_isfinite" != yes || - test "$ISFINITE_LIBM" = missing; then + dnl On Solaris 10, with CC in C++ mode, isfinite is not available although + dnl is with cc in C mode. This cannot be worked around by defining + dnl _XOPEN_SOURCE=600, because the latter does not work in C++ mode on + dnl Solaris 11.0. Therefore use the replacement functions on Solaris. + if test "$ac_cv_have_decl_isfinite" != yes \ + || test "$ISFINITE_LIBM" = missing \ + || { case "$host_os" in solaris*) true;; *) false;; esac; }; then REPLACE_ISFINITE=1 dnl No libraries are needed to link lib/isfinite.c. ISFINITE_LIBM= diff --git a/m4/isinf.m4 b/m4/isinf.m4 index 9bafc53..920be7e 100644 --- a/m4/isinf.m4 +++ b/m4/isinf.m4 @@ -1,4 +1,4 @@ -# isinf.m4 serial 12 +# isinf.m4 serial 13 dnl Copyright (C) 2007-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_ISINF], [ AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl Persuade glibc <math.h> to declare isinf. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_CHECK_DECLS([isinf], , , @@ -26,8 +27,13 @@ AC_DEFUN([gl_ISINF], esac fi fi - if test "$ac_cv_have_decl_isinf" != yes || - test "$ISINF_LIBM" = missing; then + dnl On Solaris 10, with CC in C++ mode, isinf is not available although + dnl is with cc in C mode. This cannot be worked around by defining + dnl _XOPEN_SOURCE=600, because the latter does not work in C++ mode on + dnl Solaris 11.0. Therefore use the replacement functions on Solaris. + if test "$ac_cv_have_decl_isinf" != yes \ + || test "$ISINF_LIBM" = missing \ + || { case "$host_os" in solaris*) true;; *) false;; esac; }; then REPLACE_ISINF=1 dnl No libraries are needed to link lib/isinf.c. ISINF_LIBM= diff --git a/m4/signbit.m4 b/m4/signbit.m4 index 097682b..2718aef 100644 --- a/m4/signbit.m4 +++ b/m4/signbit.m4 @@ -1,4 +1,4 @@ -# signbit.m4 serial 18 +# signbit.m4 serial 19 dnl Copyright (C) 2007-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_SIGNBIT], [ AC_REQUIRE([gl_MATH_H_DEFAULTS]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_REQUIRE([AC_CANONICAL_HOST]) AC_CACHE_CHECK([for signbit macro], [gl_cv_func_signbit], [ AC_RUN_IFELSE( @@ -90,79 +90,90 @@ AC_DEFUN([gl_SIGNBIT], *) dnl REPLACE_SIGNBIT=1 makes sure the signbit[fdl] functions get built. REPLACE_SIGNBIT=1 - gl_FLOAT_SIGN_LOCATION - gl_DOUBLE_SIGN_LOCATION - gl_LONG_DOUBLE_SIGN_LOCATION - if test "$gl_cv_cc_float_signbit" = unknown; then - dnl Test whether copysignf() is declared. - AC_CHECK_DECLS([copysignf], , , [[#include <math.h>]]) - if test "$ac_cv_have_decl_copysignf" = yes; then - dnl Test whether copysignf() can be used without libm. - AC_CACHE_CHECK([whether copysignf can be used without linking with libm], - [gl_cv_func_copysignf_no_libm], - [ - AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[#include <math.h> - float x, y;]], - [[return copysignf (x, y) < 0;]])], - [gl_cv_func_copysignf_no_libm=yes], - [gl_cv_func_copysignf_no_libm=no]) - ]) - if test $gl_cv_func_copysignf_no_libm = yes; then - AC_DEFINE([HAVE_COPYSIGNF_IN_LIBC], [1], - [Define if the copysignf function is declared in <math.h> and available in libc.]) - fi - fi - fi - if test "$gl_cv_cc_double_signbit" = unknown; then - dnl Test whether copysign() is declared. - AC_CHECK_DECLS([copysign], , , [[#include <math.h>]]) - if test "$ac_cv_have_decl_copysign" = yes; then - dnl Test whether copysign() can be used without libm. - AC_CACHE_CHECK([whether copysign can be used without linking with libm], - [gl_cv_func_copysign_no_libm], - [ - AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[#include <math.h> - double x, y;]], - [[return copysign (x, y) < 0;]])], - [gl_cv_func_copysign_no_libm=yes], - [gl_cv_func_copysign_no_libm=no]) - ]) - if test $gl_cv_func_copysign_no_libm = yes; then - AC_DEFINE([HAVE_COPYSIGN_IN_LIBC], [1], - [Define if the copysign function is declared in <math.h> and available in libc.]) - fi - fi - fi - if test "$gl_cv_cc_long_double_signbit" = unknown; then - dnl Test whether copysignl() is declared. - AC_CHECK_DECLS([copysignl], , , [[#include <math.h>]]) - if test "$ac_cv_have_decl_copysignl" = yes; then - dnl Test whether copysignl() can be used without libm. - AC_CACHE_CHECK([whether copysignl can be used without linking with libm], - [gl_cv_func_copysignl_no_libm], - [ - AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[#include <math.h> - long double x, y;]], - [[return copysignl (x, y) < 0;]])], - [gl_cv_func_copysignl_no_libm=yes], - [gl_cv_func_copysignl_no_libm=no]) - ]) - if test $gl_cv_func_copysignl_no_libm = yes; then - AC_DEFINE([HAVE_COPYSIGNL_IN_LIBC], [1], - [Define if the copysignl function is declared in <math.h> and available in libc.]) - fi - fi - fi ;; esac ;; esac + dnl On Solaris 10, with CC in C++ mode, signbit is not available although + dnl is with cc in C mode. This cannot be worked around by defining + dnl _XOPEN_SOURCE=600, because the latter does not work in C++ mode on + dnl Solaris 11.0. Therefore use the replacement functions on Solaris. + case "$host_os" in + solaris*) + REPLACE_SIGNBIT=1 + ;; + esac + if test $REPLACE_SIGNBIT = 1; then + gl_FLOAT_SIGN_LOCATION + gl_DOUBLE_SIGN_LOCATION + gl_LONG_DOUBLE_SIGN_LOCATION + if test "$gl_cv_cc_float_signbit" = unknown; then + dnl Test whether copysignf() is declared. + AC_CHECK_DECLS([copysignf], , , [[#include <math.h>]]) + if test "$ac_cv_have_decl_copysignf" = yes; then + dnl Test whether copysignf() can be used without libm. + AC_CACHE_CHECK([whether copysignf can be used without linking with libm], + [gl_cv_func_copysignf_no_libm], + [ + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include <math.h> + float x, y;]], + [[return copysignf (x, y) < 0;]])], + [gl_cv_func_copysignf_no_libm=yes], + [gl_cv_func_copysignf_no_libm=no]) + ]) + if test $gl_cv_func_copysignf_no_libm = yes; then + AC_DEFINE([HAVE_COPYSIGNF_IN_LIBC], [1], + [Define if the copysignf function is declared in <math.h> and available in libc.]) + fi + fi + fi + if test "$gl_cv_cc_double_signbit" = unknown; then + dnl Test whether copysign() is declared. + AC_CHECK_DECLS([copysign], , , [[#include <math.h>]]) + if test "$ac_cv_have_decl_copysign" = yes; then + dnl Test whether copysign() can be used without libm. + AC_CACHE_CHECK([whether copysign can be used without linking with libm], + [gl_cv_func_copysign_no_libm], + [ + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include <math.h> + double x, y;]], + [[return copysign (x, y) < 0;]])], + [gl_cv_func_copysign_no_libm=yes], + [gl_cv_func_copysign_no_libm=no]) + ]) + if test $gl_cv_func_copysign_no_libm = yes; then + AC_DEFINE([HAVE_COPYSIGN_IN_LIBC], [1], + [Define if the copysign function is declared in <math.h> and available in libc.]) + fi + fi + fi + if test "$gl_cv_cc_long_double_signbit" = unknown; then + dnl Test whether copysignl() is declared. + AC_CHECK_DECLS([copysignl], , , [[#include <math.h>]]) + if test "$ac_cv_have_decl_copysignl" = yes; then + dnl Test whether copysignl() can be used without libm. + AC_CACHE_CHECK([whether copysignl can be used without linking with libm], + [gl_cv_func_copysignl_no_libm], + [ + AC_LINK_IFELSE( + [AC_LANG_PROGRAM( + [[#include <math.h> + long double x, y;]], + [[return copysignl (x, y) < 0;]])], + [gl_cv_func_copysignl_no_libm=yes], + [gl_cv_func_copysignl_no_libm=no]) + ]) + if test $gl_cv_func_copysignl_no_libm = yes; then + AC_DEFINE([HAVE_COPYSIGNL_IN_LIBC], [1], + [Define if the copysignl function is declared in <math.h> and available in libc.]) + fi + fi + fi + fi ]) AC_DEFUN([gl_SIGNBIT_TEST_PROGRAM], [[
