From patchwork Thu Sep 29 10:58:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 676600 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3slBQ16L9rz9s9Y for ; Thu, 29 Sep 2016 20:58:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=OktishTm; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=YFywJf22FfNuCZJx9 ced17sicFFXMxWAAc2DGtUUUsIdR2kLhlOshKt0AqqI9DCiPU+EkTjQhqhWf1G41 0hHhhhFERNihkPB/CA9keHV2ak20a4OiMigvNeF/5Zt7GWqr8K7jpQ0VPlZqc6rz QzWQ2LfQ2nNWKCBUm6/1PdSve4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=wr1zEDbuO9bKd35FD2B8csM vYTQ=; b=OktishTmxp16hhZQ9LfjxUWukeDbcr8r1t6AFZILRwH33ktjXsv61Xl PFwSDRhYWj75avcwLnz5fsPmYA6q0Iyzr4pwwvlI/hI1XObyeBmaToP3Y8kAR22K 0v7FX7zGAwiCXylb788SHRxqqxsER+7HUhgaCucu4A/ugxpc/eg0= Received: (qmail 73391 invoked by alias); 29 Sep 2016 10:58:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 72393 invoked by uid 89); 29 Sep 2016 10:58:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=declarations, dear, Dear, team X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Sep 2016 10:58:11 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EFAE3F1EC; Thu, 29 Sep 2016 10:58:10 +0000 (UTC) Received: from localhost (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8TAw8Xt002211; Thu, 29 Sep 2016 06:58:09 -0400 Date: Thu, 29 Sep 2016 11:58:08 +0100 From: Jonathan Wakely To: Rainer Orth Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Define 3-argument overloads of std::hypot for C++17 (P0030R1) Message-ID: <20160929105807.GJ29482@redhat.com> References: <20160927151158.GA6188@redhat.com> <20160929091049.GE29482@redhat.com> <20160929092418.GF29482@redhat.com> <20160929104758.GI29482@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160929104758.GI29482@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) On 29/09/16 11:47 +0100, Jonathan Wakely wrote: >On 29/09/16 12:39 +0200, Rainer Orth wrote: >>Hi Jonathan, >> >>>>That would suggest Solaris uses include/c_std/cmath (where I forgot to >>>>add the new overloads) rather than include/c_global/cmath ... is that >>>>right? >>> >>>Alternatively it's using c_global/cmath but _GLIBCXX_USE_C99_MATH_TR1 >>>is not defined, as the new overloads are inside that block. I thought >>>that was defined for Solaris though, which is why we have the >>>__CORRECT_ISO_CPP11_MATH_H_PROTO there in that file. >> >>it is indeed, at least initially. What I see in preprocessed input is >>this: >> >>ro@galeras 208 > grep _GLIBCXX_USE_C99_MATH testsuite/normal4/hypot.ii >>#define _GLIBCXX_USE_C99_MATH _GLIBCXX11_USE_C99_MATH >>#define _GLIBCXX_USE_C99_MATH_TR1 1 >>#undef _GLIBCXX_USE_C99_MATH >>#undef _GLIBCXX_USE_C99_MATH_TR1 >> >>It turns out the #undef's are from : >> >>#if __cplusplus >= 201103L >>#undef _GLIBCXX_USE_C99_MATH >>#undef _GLIBCXX_USE_C99_MATH_TR1 >>#endif >> >>No idea what this nonsense is trying to accomplish! It's already in >>Solaris 11.3, however. > >Wow. > >If only there was some way the Solaris team could contact us so we >could coordinate and stop adding more and more hacks to mess with each >others headers. But I assume they don't have access to the www or >email, because the only other explanation is too rude to say on a >public list. Presumably they now provide all the declarations for C++11, so we don't need to declare them. Moving the new hypot overload outside the _GLIBCXX_USE_C99_MATH_TR1 block should mean it's declared. That will break when Solaris adds C++17 support, so we'd better add some macro to guard the new hypot overloads, so they can be disabled again. Let's call it __CORRECT_ISO_CPP17_MATH_H_PROTO (and maybe add a coment like "Dear Solaris team, ..."). Does this work? diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath index fffa0e7..86ffd34 100644 --- a/libstdc++-v3/include/c_global/cmath +++ b/libstdc++-v3/include/c_global/cmath @@ -1455,46 +1455,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return hypot(__type(__x), __type(__y)); } -#if __cplusplus > 201402L -#define __cpp_lib_hypot 201603 - // [c.math.hypot3], three-dimensional hypotenuse - - template - inline _Tp - __hypot3(_Tp __x, _Tp __y, _Tp __z) - { - __x = std::abs(__x); - __y = std::abs(__y); - __z = std::abs(__z); - if (_Tp __a = __x < __y ? __y < __z ? __z : __y : __x < __z ? __z : __x) - return __a * std::sqrt((__x / __a) * (__x / __a) - + (__y / __a) * (__y / __a) - + (__z / __a) * (__z / __a)); - else - return {}; - } - - inline float - hypot(float __x, float __y, float __z) - { return std::__hypot3(__x, __y, __z); } - - inline double - hypot(double __x, double __y, double __z) - { return std::__hypot3(__x, __y, __z); } - - inline long double - hypot(long double __x, long double __y, long double __z) - { return std::__hypot3(__x, __y, __z); } - - template - typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type - hypot(_Tp __x, _Up __y, _Vp __z) - { - using __type = typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type; - return std::__hypot3<__type>(__x, __y, __z); - } -#endif // C++17 - #ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO constexpr int ilogb(float __x) @@ -1830,6 +1790,55 @@ _GLIBCXX_END_NAMESPACE_VERSION #endif // C++11 +#if __cplusplus > 201402L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +#ifndef __CORRECT_ISO_CPP17_MATH_H_PROTO + // [c.math.hypot3], three-dimensional hypotenuse +#define __cpp_lib_hypot 201603 + + template + inline _Tp + __hypot3(_Tp __x, _Tp __y, _Tp __z) + { + __x = std::abs(__x); + __y = std::abs(__y); + __z = std::abs(__z); + if (_Tp __a = __x < __y ? __y < __z ? __z : __y : __x < __z ? __z : __x) + return __a * std::sqrt((__x / __a) * (__x / __a) + + (__y / __a) * (__y / __a) + + (__z / __a) * (__z / __a)); + else + return {}; + } + + inline float + hypot(float __x, float __y, float __z) + { return std::__hypot3(__x, __y, __z); } + + inline double + hypot(double __x, double __y, double __z) + { return std::__hypot3(__x, __y, __z); } + + inline long double + hypot(long double __x, long double __y, long double __z) + { return std::__hypot3(__x, __y, __z); } + + template + typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type + hypot(_Tp __x, _Up __y, _Vp __z) + { + using __type = typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type; + return std::__hypot3<__type>(__x, __y, __z); +#endif + } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace +#endif // C++17 + + #if _GLIBCXX_USE_STD_SPEC_FUNCS # include #endif