Patchwork [v3] avoid duplicate definitions in <tr1/complex> in C++0x mode

login
register
mail settings
Submitter Jonathan Wakely
Date Feb. 12, 2011, 6:30 p.m.
Message ID <AANLkTikpz8htSWBPPFG4pDUQ6xuRBmHDAJLr_OPOW1wc@mail.gmail.com>
Download mbox | patch
Permalink /patch/82941/
State New
Headers show

Comments

Jonathan Wakely - Feb. 12, 2011, 6:30 p.m.
2011-02-12  Paolo Carlini  <paolo.carlini@oracle.com>

        * include/tr1/cmath (fabs): Define.
        * include/tr1/complex (acos, asin, atan): Avoid duplicate definitions
        in C++0x mode.

2011-02-12  Jonathan Wakely  <jwakely.gcc@gmail.com>

        * testsuite/tr1/headers/c++200x/complex.cc: New.

tested x86_64-linux, committed to trunk

Patch

Index: include/tr1/cmath
===================================================================
--- include/tr1/cmath	(revision 169994)
+++ include/tr1/cmath	(working copy)
@@ -1,6 +1,7 @@ 
 // TR1 cmath -*- C++ -*-
 
-// Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
+// 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
@@ -575,7 +576,24 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return expm1(__type(__x));
     }
 
-  using std::fabs;
+  // Note: we deal with fabs in a special way, because an using std::fabs
+  // would bring in also the overloads for complex types, which in C++0x
+  // mode have a different return type.
+  using ::fabs;
+
+  inline float
+  fabs(float __x)
+  { return __builtin_fabsf(__x); }
+
+  inline long double
+  fabs(long double __x)
+  { return __builtin_fabsl(__x); }
+
+  template<typename _Tp>
+    inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, 
+					   double>::__type
+    fabs(_Tp __x)
+    { return __builtin_fabs(__x); }
 
   inline float
   fdim(float __x, float __y)
Index: include/tr1/complex
===================================================================
--- include/tr1/complex	(revision 169994)
+++ include/tr1/complex	(working copy)
@@ -1,6 +1,7 @@ 
 // TR1 complex -*- C++ -*-
 
-// Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
+// 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
@@ -44,16 +45,24 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
    * @{
    */
 
-  // Forward declarations.
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  using std::acos;
+  using std::asin;
+  using std::atan;
+#else
   template<typename _Tp> std::complex<_Tp> acos(const std::complex<_Tp>&);
   template<typename _Tp> std::complex<_Tp> asin(const std::complex<_Tp>&);
   template<typename _Tp> std::complex<_Tp> atan(const std::complex<_Tp>&);
+#endif
 
   template<typename _Tp> std::complex<_Tp> acosh(const std::complex<_Tp>&);
   template<typename _Tp> std::complex<_Tp> asinh(const std::complex<_Tp>&);
   template<typename _Tp> std::complex<_Tp> atanh(const std::complex<_Tp>&);
+
+  // The std::fabs return type in C++0x mode is different (just _Tp).
   template<typename _Tp> std::complex<_Tp> fabs(const std::complex<_Tp>&);
 
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
   template<typename _Tp>
     inline std::complex<_Tp>
     __complex_acos(const std::complex<_Tp>& __z)
@@ -170,6 +179,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { return __complex_atan(__z); }
 #endif
 
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
   template<typename _Tp>
     std::complex<_Tp>
     __complex_acosh(const std::complex<_Tp>& __z)
Index: testsuite/tr1/headers/c++200x/complex.cc
===================================================================
--- testsuite/tr1/headers/c++200x/complex.cc	(revision 0)
+++ testsuite/tr1/headers/c++200x/complex.cc	(revision 0)
@@ -0,0 +1,26 @@ 
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2011 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 3, 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 COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// check for duplicates of complex overloads of acos, asin, atan and fabs
+
+#include <complex>
+#include <tr1/cmath>
+#include <tr1/complex>
+