From: Bruno Haible Date: Sat, 17 Dec 2016 19:44:37 +0000 (+0100) Subject: sqrtf: Avoid redefinition error on MSVC. X-Git-Tag: v1.0~6463 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c7a2c318d3e7af5331ff5571125702c0c57546f6;p=gnulib.git sqrtf: Avoid redefinition error on MSVC. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Define REPLACE_SQRTF. * m4/sqrtf.m4 (gl_FUNC_SQRTF): Set REPLACE_SQRTF to 1 if the function may be defined as an inline function. * modules/math (Makefile.am): Substitute REPLACE_SQRTF. * lib/math.in.h (sqrtf): Override if REPLACE_SQRTF is 1. --- diff --git a/ChangeLog b/ChangeLog index 55393eb102..a6593b18c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2016-12-17 Bruno Haible + + sqrtf: Avoid redefinition error on MSVC. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Define REPLACE_SQRTF. + * m4/sqrtf.m4 (gl_FUNC_SQRTF): Set REPLACE_SQRTF to 1 if the function + may be defined as an inline function. + * modules/math (Makefile.am): Substitute REPLACE_SQRTF. + * lib/math.in.h (sqrtf): Override if REPLACE_SQRTF is 1. + 2016-12-17 Bruno Haible sinhf: Avoid redefinition error on MSVC. diff --git a/lib/math.in.h b/lib/math.in.h index 05aa8eafdd..842a6369b2 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1955,11 +1955,20 @@ _GL_WARN_ON_USE (sinhf, "sinhf is unportable - " #if @GNULIB_SQRTF@ -# if !@HAVE_SQRTF@ -# undef sqrtf +# if @REPLACE_SQRTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef sqrtf +# define sqrtf rpl_sqrtf +# endif +_GL_FUNCDECL_RPL (sqrtf, float, (float x)); +_GL_CXXALIAS_RPL (sqrtf, float, (float x)); +# else +# if !@HAVE_SQRTF@ +# undef sqrtf _GL_FUNCDECL_SYS (sqrtf, float, (float x)); -# endif +# endif _GL_CXXALIAS_SYS (sqrtf, float, (float x)); +# endif _GL_CXXALIASWARN (sqrtf); #elif defined GNULIB_POSIXCHECK # undef sqrtf diff --git a/m4/math_h.m4 b/m4/math_h.m4 index eac869209f..cb415936e8 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -324,6 +324,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_SIGNBIT_USING_GCC=0; AC_SUBST([REPLACE_SIGNBIT_USING_GCC]) REPLACE_SINF=0; AC_SUBST([REPLACE_SINF]) REPLACE_SINHF=0; AC_SUBST([REPLACE_SINHF]) + REPLACE_SQRTF=0; AC_SUBST([REPLACE_SQRTF]) REPLACE_SQRTL=0; AC_SUBST([REPLACE_SQRTL]) REPLACE_TRUNC=0; AC_SUBST([REPLACE_TRUNC]) REPLACE_TRUNCF=0; AC_SUBST([REPLACE_TRUNCF]) diff --git a/m4/sqrtf.m4 b/m4/sqrtf.m4 index ae9570f02b..a6fee07ded 100644 --- a/m4/sqrtf.m4 +++ b/m4/sqrtf.m4 @@ -1,4 +1,4 @@ -# sqrtf.m4 serial 2 +# sqrtf.m4 serial 3 dnl Copyright (C) 2011-2016 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -22,6 +22,10 @@ AC_DEFUN([gl_FUNC_SQRTF], SQRTF_LIBM="$SQRT_LIBM" else HAVE_SQRTF=0 + dnl If the function is declared but does not appear to exist, it may be + dnl defined as an inline function. In order to avoid a conflict, we have + dnl to define rpl_sqrtf, not sqrtf. + AC_CHECK_DECLS([sqrtf], [REPLACE_SQRTF=1], , [[#include ]]) SQRTF_LIBM="$SQRT_LIBM" fi AC_SUBST([SQRTF_LIBM]) diff --git a/modules/math b/modules/math index d674e14499..a22d369fa8 100644 --- a/modules/math +++ b/modules/math @@ -294,6 +294,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \ -e 's|@''REPLACE_SINF''@|$(REPLACE_SINF)|g' \ -e 's|@''REPLACE_SINHF''@|$(REPLACE_SINHF)|g' \ + -e 's|@''REPLACE_SQRTF''@|$(REPLACE_SQRTF)|g' \ -e 's|@''REPLACE_SQRTL''@|$(REPLACE_SQRTL)|g' \ -e 's|@''REPLACE_TRUNC''@|$(REPLACE_TRUNC)|g' \ -e 's|@''REPLACE_TRUNCF''@|$(REPLACE_TRUNCF)|g' \