[fixincludes, v3] Don't define libstdc++-internal macros in Solaris 10+ <math.h>

Rainer Orth ro@CeBiTec.Uni-Bielefeld.DE
Fri Nov 18 11:10:00 GMT 2016


Hi Jonathan,

> On 03/11/16 15:11 +0100, Rainer Orth wrote:
>>Fortunately, this is all easily fixed by wrapping the affected templates
>>in a new macro.  That's what this patch does.  The new libstdc++
>>acinclude.m4 test may well need wording changes in comments etc. and can
>>perhaps be shortened a bit, bit it worked for me.
>
> See below.

thanks for the thorough review.

> The change is OK in principle, but I'd prefer more meaningful names
> for the macros ...

Fine with me: I know close to nothing of C++, so please bear with me ;-)

>>--- a/libstdc++-v3/acinclude.m4
>>+++ b/libstdc++-v3/acinclude.m4
>>@@ -2181,7 +2181,8 @@ AC_DEFUN([GLIBCXX_CHECK_STDIO_PROTO], [
>> ])
>>
>> dnl
>>-dnl Check whether required C++11 overloads are present in <math.h>.
>>+dnl Check whether required C++11 overloads and templates are present
>>+dnl in <math.h>.
>
> The standard doesn't actually require templates to be used here, it
> only requires "sufficient additional overloads" so that integral
> arguments work. We happen to do that with templates, and apparently so
> do the Solaris headers, but other implementations are possible. So a
> more accurate description would be:
>
> dnl Check whether required C++11 overloads for FP and integral types
> dnl are present in <math.h>.
>
> And rather than PROTO1 and PROTO2 the macros could be called PROTO_FP
> for the overloads for FP types, and PROTO_INT (or just PROTO_I) for
> the overloads for integral types (which happen to be templates in our
> header).

I went for the longer/more expressive names.

> The suggestions above would make it shorter, while still remaining
> accurate to what the real code in the header does. It could be reduced
> even further without altering the meaning for the purposes of this
> test:
>
>>+	   namespace std {
>>+	     template<typename _Tp>
>>+	       constexpr typename __gnu_cxx::__enable_if
>>+	       		 <__is_integer<_Tp>::__value, double>::__type
>>+	       log2(_Tp __x)
>>+	       { return __builtin_log2(__x); }
>
> 	     template<typename _Tp>
> 	       struct __enable_if_int;
>
> 	     template<>
> 	       struct __enable_if_int<int>
> 	       { typedef double __type; };
>
> 	     template<typename _Tp>
> 	       constexpr typename __enable_if_int<_Tp>::__type
> 	       log2(_Tp __x)
> 	       { return __builtin_log2(__x); }
>
> I don't mind whether you go with this or just remove the unnecessary
> structs, typedef and primary template bodies. Either is OK.

I went for the latter to keep the testcase close to the original.

Please find attached the revised version of the patch.  I hope I've
incorporated all of your comments.

@Bruce: To avoid the hpux11_fabsf test breakage from my original
fixincludes part, Dave suggested in private mail to replace the

  bypass = '__cplusplus'

by

  mach   = '*-hp-hpux11*'

so the fix only applies to the systems that need them and doesn't
get interference from other testcases.  So I've got clean make check
results in fixincludes.

The patch has again been bootstrapped without regressions on
i386-pc-solaris2.12, sparc-sun-solaris2.12, i386-pc-solaris2.11 (both
with only the fp overloads and nothing at all), and
x86_64-pc-linux-gnu.

I plan to repeat that testing on the gcc-6 and gcc-5 branches;
differences between the branches were minimal for the previons versions
(like regenerating fixincl.x or an adjacent comment difference in
c_global/cmath).

Ok for mainline now and the backports after some soak time?

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2016-10-27  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
	    John David Anglin  <danglin@gcc.gnu.org>

	libstdc++-v3:
	* acinclude.m4 (GLIBCXX_CHECK_MATH11_PROTO): Update comments.
	(__CORRECT_ISO_CPP11_MATH_H_PROTO): Rename to ...
	(__CORRECT_ISO_CPP11_MATH_H_PROTO_FP): ... this.
	Add test for C++11 <math.h> templates.
	* configure: Regenerate.
	* config.h.in: Regenerate.

	* include/c_global/cmath [__cplusplus >= 201103L]: Reflect
	__CORRECT_ISO_CPP11_MATH_H_PROTO to
	__CORRECT_ISO_CPP11_MATH_H_PROTO_FP rename.
	* include/c_global/cmath [_GLIBCXX_USE_C99_MATH &&
	!_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC && __cplusplus >= 201103L]
	(std::fpclassify): Wrap in !__CORRECT_ISO_CPP11_MATH_H_PROTO_INT.
	(std::isfinite): Likewise.
	(std::isinf): Likewise.
	(std::isnan): Likewise.
	(std::isnormal): Likewise.
	(std::signbit): Likewise.
	(std::isgreater): Likewise.
	(std::isgreaterequal): Likewise.
	(std::isless): Likewise.
	(std::islessequal): Likewise.
	(std::islessgreater): Likewise.
	(std::isunordered): Likewise.
	[__cplusplus >= 201103L && _GLIBCXX_USE_C99_MATH_TR1]
	(std::acosh): Likewise.
	(std::asinh): Likewise.
	(std::atanh): Likewise.
	(std::cbrt): Likewise.
	(std::copysign): Likewise.
	(std::erf): Likewise.
	(std::erfc): Likewise.
	(std::exp2): Likewise.
	(std::expm1): Likewise.
	(std::fdim): Likewise.
	(std::fma): Likewise.
	(std::fmax): Likewise.
	(std::fmin): Likewise.
	(std::hypot): Likewise.
	(std::ilogb): Likewise.
	(std::lgamma): Likewise.
	(std::llrint): Likewise.
	(std::llround): Likewise.
	(std::log1p): Likewise.
	(std::log2): Likewise.
	(std::logb): Likewise.
	(std::lrint): Likewise.
	(std::lround): Likewise.
	(std::nearbyint): Likewise.
	(std::nextafter): Likewise.
	(std::nexttoward): Likewise.
	(std::remainder): Likewise.
	(std::remquo): Likewise.
	(std::rint): Likewise.
	(std::round): Likewise.
	(std::scalbln): Likewise.
	(std::scalbn): Likewise.
	(std::tgamma): Likewise.
	(std::trunc): Likewise.
	* include/tr1/cmath [_GLIBCXX_USE_C99_MATH_TR1 && __cplusplus >=
	201103L]: Reflect __CORRECT_ISO_CPP11_MATH_H_PROTO to
	__CORRECT_ISO_CPP11_MATH_H_PROTO_FP rename.

	fixincludes:
	* inclhack.def (solaris_math_12): New fix.
	(hpux11_fabsf): Replace bypass by *-hp-hpux11* mach selector.
	* fixincl.x: Regenerate.
	* tests/base/math.h [SOLARIS_MATH_12_CHECK]: New test.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sol2-math-glibcxx.patch
Type: text/x-patch
Size: 43443 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20161118/49fb29cb/attachment.bin>


More information about the Libstdc++ mailing list