This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[PATCH] Fix std::pow and std::atan2 on 4.3 branch (PR libstdc++/37582)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: Fri, 12 Dec 2008 09:51:04 +0100
- Subject: [PATCH] Fix std::pow and std::atan2 on 4.3 branch (PR libstdc++/37582)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The 4.3 branch doesn't have DR339 resolved as 4.4 has
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133519
but that patch seems to be inappropriate to the branch at this point.
As the headers already use __traitor which casts both values to
bool, this introduces similar __traitand.
Bootstrapped/regtested on x86_64-linux, pre-approved by Paolo, committed
to 4.3 branch.
Is the testcase alone ok for the trunk as well?
2008-12-11 Jakub Jelinek <jakub@redhat.com>
PR c++/37582
* include/bits/cpp_type_traits.h (struct __traitand): New.
* include/c_global/cmath (std::atan2, std::pow): Use __traitand
instead of && as first argument to __enable_if.
* include/c_std/cmath (std::atan2): Likewise.
* testsuite/26_numerics/headers/cmath/37582.cc: New.
--- libstdc++-v3/include/bits/cpp_type_traits.h.jj 2008-10-22 20:37:52.000000000 +0200
+++ libstdc++-v3/include/bits/cpp_type_traits.h 2008-12-12 00:13:16.000000000 +0100
@@ -100,6 +100,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
typedef typename __truth_type<__value>::__type __type;
};
+ // N.B. The conversions to bool are needed due to the issue
+ // explained in c++/19404.
+ template<class _Sp, class _Tp>
+ struct __traitand
+ {
+ enum { __value = bool(_Sp::__value) && bool(_Tp::__value) };
+ typedef typename __truth_type<__value>::__type __type;
+ };
+
// Compare for equality of types.
template<typename, typename>
struct __are_same
--- libstdc++-v3/include/c_global/cmath.jj 2008-10-22 20:37:52.000000000 +0200
+++ libstdc++-v3/include/c_global/cmath 2008-12-12 00:13:16.000000000 +0100
@@ -168,8 +168,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp, typename _Up>
inline
typename __gnu_cxx::__promote_2<
- typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value
- && __is_arithmetic<_Up>::__value,
+ typename __gnu_cxx::__enable_if<__traitand<__is_arithmetic<_Tp>,
+ __is_arithmetic<_Up> >::__value,
_Tp>::__type, _Up>::__type
atan2(_Tp __y, _Up __x)
{
@@ -383,8 +383,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<typename _Tp, typename _Up>
inline
typename __gnu_cxx::__promote_2<
- typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value
- && __is_arithmetic<_Up>::__value,
+ typename __gnu_cxx::__enable_if<__traitand<__is_arithmetic<_Tp>,
+ __is_arithmetic<_Up> >::__value,
_Tp>::__type, _Up>::__type
pow(_Tp __x, _Up __y)
{
--- libstdc++-v3/include/c_std/cmath.jj 2008-10-22 20:37:54.000000000 +0200
+++ libstdc++-v3/include/c_std/cmath 2008-12-12 00:13:16.000000000 +0100
@@ -157,9 +157,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ return __builtin_atan2l(__y, __x); }
template<typename _Tp, typename _Up>
- inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value
- && __is_integer<_Up>::__value,
- double>::__type
+ inline
+ typename __gnu_cxx::__enable_if<__traitand<__is_integer<_Tp>,
+ __is_integer<_Up> >::__value,
+ double>::__type
atan2(_Tp __y, _Up __x)
{ return __builtin_atan2(__y, __x); }
--- libstdc++-v3/testsuite/26_numerics/headers/cmath/37582.cc.jj 2008-12-12 09:31:11.000000000 +0100
+++ libstdc++-v3/testsuite/26_numerics/headers/cmath/37582.cc 2008-12-12 09:38:21.000000000 +0100
@@ -0,0 +1,44 @@
+// Copyright (C) 2008 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// { dg-do compile }
+
+#include <cmath>
+
+struct foo
+{
+ foo (double);
+};
+
+bool operator &&(int, const foo &);
+
+// libstdc++/37582
+double
+test01(double x)
+{
+ return std::pow (x, 2.0);
+}
Jakub