This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Fix overloading issue in <cmath>


Loren James Rittle <rittle@latour.rsch.comm.mot.com> writes:

[...]

| Along that line, if possible, please install a new test case and
| report what platform it fails upon without the patch (unless it indeed
| merely fixes an existing test case).

That patch actually fixes PR libstdc++/3181 reported on
i686-pc-linux-gnu, but is thought to be platform independent.  Those on
which it wasn't failing are broken :->

Applied as below.

-- Gaby

Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/ChangeLog,v
retrieving revision 1.1710
diff -p -r1.1710 ChangeLog
*** ChangeLog	11 May 2003 04:20:53 -0000	1.1710
--- ChangeLog	11 May 2003 09:05:41 -0000
***************
*** 1,3 ****
--- 1,30 ----
+ 2003-05-11  Gabriel Dos Reis <gdr@integrable-solutions.net>
+ 
+ 	PR libstdc++/3181
+ 	* include/c_std/std_cmath.h: #include <bits/cpp_type_traits.h>
+ 	(acos): Handle integer argument.
+ 	(asin): Likewise.
+ 	(atan): Likewise.
+ 	(atan2): Likewise.
+ 	(ceil): Likewise.
+ 	(cos): Likewise.
+ 	(cosh): Likewise.
+ 	(exp): Likewise.
+ 	(fabs): Likewise.
+ 	(floor): Likewise.
+ 	(frexp): Likewise.
+ 	(ldexp): Likewise.
+ 	(log): Likewise.
+ 	(log10): Likewise.
+ 	(sin): Likewise.
+ 	(sinh): Likewise.
+ 	(sqrt): Likewise.
+ 	(tan): Likewise.
+ 	(tanh): Likewise.
+ 	* include/bits/cpp_type_traits.h (__are_same<>): New traits.
+ 	(__enable_if): Likewise.
+ 	* testsuite/26_numerics/cmath/overloads.C: New test.
+ 	
  2003-05-10  Petur Runolfsson  <peturr02@ru.is>
  
  	PR libstdc++/9027
Index: include/bits/cpp_type_traits.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/cpp_type_traits.h,v
retrieving revision 1.6
diff -p -r1.6 cpp_type_traits.h
*** include/bits/cpp_type_traits.h	16 Jan 2002 19:57:30 -0000	1.6
--- include/bits/cpp_type_traits.h	11 May 2003 09:05:41 -0000
***************
*** 1,6 ****
  // The  -*- C++ -*- type traits classes for internal use in libstdc++
  
! // Copyright (C) 2000, 2001 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
--- 1,6 ----
  // The  -*- C++ -*- type traits classes for internal use in libstdc++
  
! // Copyright (C) 2000, 2001, 2002, 2003 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
***************
*** 66,71 ****
--- 66,103 ----
  
  namespace std
  {
+   // Compare for equality of types.
+   template<typename, typename>
+     struct __are_same
+     {
+       enum
+       {
+         _M_type = 0
+       };
+     };
+ 
+   template<typename _Tp>
+     struct __are_same<_Tp, _Tp>
+     {
+       enum
+       {
+         _M_type = 1
+       };
+     };
+ 
+   // Define a nested type if some predicate holds.
+   template<typename, bool>
+     struct __enable_if
+     {
+     };
+ 
+   template<typename _Tp>
+   struct __enable_if<_Tp, true>
+     {
+       typedef _Tp _M_type;
+     };
+ 
+   // Holds if the template-argument is a void type.
    template<typename _Tp>
      struct __is_void
      {
Index: include/c_std/std_cmath.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/c_std/std_cmath.h,v
retrieving revision 1.8
diff -p -r1.8 std_cmath.h
*** include/c_std/std_cmath.h	18 Apr 2003 06:58:42 -0000	1.8
--- include/c_std/std_cmath.h	11 May 2003 09:05:41 -0000
***************
*** 47,52 ****
--- 47,53 ----
  #pragma GCC system_header
  
  #include <bits/c++config.h>
+ #include <bits/cpp_type_traits.h>
  
  #include <math.h>
  
*************** namespace std 
*** 197,202 ****
--- 198,210 ----
    acos(long double __x) { return ::acos(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     acos(_Tp __x)
+     {
+       return ::acos(static_cast<double>(__x));
+     }
+   
    using ::asin;
  
  #if _GLIBCPP_HAVE_ASINF
*************** namespace std 
*** 215,220 ****
--- 223,233 ----
    asin(long double __x) { return ::asin(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     asin(_Tp __x)
+     { return ::asin(static_cast<double>(__x)); }
+ 
    using ::atan;
  
  #if _GLIBCPP_HAVE_ATANF
*************** namespace std 
*** 233,238 ****
--- 246,256 ----
    atan(long double __x) { return ::atan(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     atan(_Tp __x)
+     { return ::atan(static_cast<double>(__x)); }
+   
    using ::atan2;
  
  #if _GLIBCPP_HAVE_ATAN2F
*************** namespace std 
*** 253,258 ****
--- 271,282 ----
    { return ::atan2(static_cast<double>(__y), static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp, typename _Up>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type
+                                         && __is_integer<_Up>::_M_type>::_M_type
+     atan2(_Tp __x, _Up __y)
+     { return ::atan2(static_cast<double>(__x), static_cast<double>(__y)); }
+ 
    using ::ceil;
  
  #if _GLIBCPP_HAVE_CEILF
*************** namespace std 
*** 271,276 ****
--- 295,305 ----
    ceil(long double __x) { return ::ceil(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     ceil(_Tp __x)
+     { return ::ceil(static_cast<double>(__x)); }
+   
    using ::cos;
  
    inline float
*************** namespace std 
*** 281,286 ****
--- 310,320 ----
    cos(long double __x)
    { return __builtin_cosl(__x); }
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     cos(_Tp __x)
+     { return __builtin_cos(__x); }
+ 
    using ::cosh;
  
  #if _GLIBCPP_HAVE_COSHF
*************** namespace std 
*** 299,304 ****
--- 333,343 ----
    cosh(long double __x) { return ::cosh(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     cosh(_Tp __x)
+     { return ::cosh(static_cast<double>(__x)); }
+ 
    using ::exp;
  
  #if _GLIBCPP_HAVE_EXPF
*************** namespace std 
*** 317,322 ****
--- 356,366 ----
    exp(long double __x) { return ::exp(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     exp(_Tp __x)
+     { return ::exp(static_cast<double>(__x)); }
+   
    using ::fabs;
  
    inline float
*************** namespace std 
*** 327,332 ****
--- 371,381 ----
    fabs(long double __x)
    { return __builtin_fabsl(__x); }
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     fabs(_Tp __x)
+     { return __builtin_fabs(__x); }
+ 
    using ::floor;
  
  #if _GLIBCPP_HAVE_FLOORF
*************** namespace std 
*** 345,350 ****
--- 394,404 ----
    floor(long double __x) { return ::floor(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     floor(_Tp __x)
+     { return ::floor(static_cast<double>(__x)); }
+   
    using ::fmod;
  
  #if _GLIBCPP_HAVE_FMODF
*************** namespace std 
*** 384,389 ****
--- 438,448 ----
    { return ::frexp(static_cast<double>(__x), __exp); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     frexp(_Tp __x, int* __exp)
+     { return ::frexp(static_cast<double>(__x), __exp); }
+   
    using ::ldexp;
  
  #if _GLIBCPP_HAVE_LDEXPF
*************** namespace std 
*** 404,409 ****
--- 463,473 ----
    { return ::ldexp(static_cast<double>(__x), __exp); }
  #endif
  
+   template<typename _Tp>
+   inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+   ldexp(_Tp __x, int __exp)
+   { return ::ldexp(static_cast<double>(__x), __exp); }
+ 
    using ::log;
  
  #if _GLIBCPP_HAVE_LOGF
*************** namespace std 
*** 422,427 ****
--- 486,496 ----
    log(long double __x) { return ::log(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     log(_Tp __x)
+     { return ::log(static_cast<double>(__x)); }
+   
    using ::log10;
  
  #if _GLIBCPP_HAVE_LOG10F
*************** namespace std 
*** 440,445 ****
--- 509,519 ----
    log10(long double __x) { return ::log10(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     log10(_Tp __x)
+     { return ::log10(static_cast<double>(__x)); }
+   
    using ::modf;
  
  #if _GLIBCPP_HAVE_MODFF
*************** namespace std 
*** 521,526 ****
--- 595,605 ----
    sin(long double __x)
    { return __builtin_sinl(__x); }
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     sin(_Tp __x)
+     { return __builtin_sin(__x); }
+ 
    using ::sinh;
  
  #if _GLIBCPP_HAVE_SINHF
*************** namespace std 
*** 539,544 ****
--- 618,628 ----
    sinh(long double __x) { return ::sinh(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     sinh(_Tp __x)
+     { return ::sinh(static_cast<_Tp>(__x)); }
+   
    using ::sqrt;
  
    inline float
*************** namespace std 
*** 549,554 ****
--- 633,643 ----
    sqrt(long double __x)
    { return __builtin_sqrtl(__x); }
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     sqrt(_Tp __x)
+     { return __builtin_sqrt(__x); }
+   
    using ::tan;
  
  #if _GLIBCPP_HAVE_TANF
*************** namespace std 
*** 567,572 ****
--- 656,666 ----
    tan(long double __x) { return ::tan(static_cast<double>(__x)); }
  #endif
  
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     tan(_Tp __x)
+     { return ::tan(static_cast<double>(__x)); }
+   
    using ::tanh;
  
  #if _GLIBCPP_HAVE_TANHF
*************** namespace std 
*** 584,589 ****
--- 678,688 ----
    inline long double 
    tanh(long double __x) { return ::tanh(static_cast<double>(__x)); }
  #endif
+ 
+   template<typename _Tp>
+     inline typename __enable_if<double, __is_integer<_Tp>::_M_type>::_M_type
+     tanh(_Tp __x)
+     { return ::tanh(static_cast<double>(__x)); }
  } 
  
  
Index: testsuite/26_numerics/cmath/overloads.C
===================================================================
RCS file: testsuite/26_numerics/cmath/overloads.C
diff -N testsuite/26_numerics/cmath/overloads.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/26_numerics/cmath/overloads.C	11 May 2003 09:05:42 -0000
***************
*** 0 ****
--- 1,27 ----
+ // PR 3181
+ // Origin: pete@toyon.com
+ 
+ #include <cmath>
+ 
+ int main()
+ {
+   int i = -1;
+   int j = 9;
+   double ans;
+   ans = std::acos(i);
+   ans = std::asin(i);
+   ans = std::atan(i);
+   ans = std::atan2(i, j);
+   ans = std::cos(i);
+   ans = std::cosh(i);
+   ans = std::exp(i);
+   ans = std::fabs(i);
+   ans = std::floor(i);
+   ans = std::log(i);
+   ans = std::log10(i);
+   ans = std::sqrt(i);
+   ans = std::sin(i);
+   ans = std::sinh(j);
+   ans = std::tan(i);
+   ans = std::tanh(i);
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]