From: Paolo Carlini Date: Mon, 26 May 2008 19:18:24 +0000 (+0000) Subject: cmath (pow(float, int), [...]): Do not define in C++0x mode, per DR 550. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=774c3d8647cc7012937cfc9d2d6dacc85b6cf8e9;p=gcc.git cmath (pow(float, int), [...]): Do not define in C++0x mode, per DR 550. 2008-05-26 Paolo Carlini * include/c_global/cmath (pow(float, int), pow(double, int), pow(long double, int)): Do not define in C++0x mode, per DR 550. * include/tr1_impl/cmath (pow): Do not bring in unconditionally from namespace std. * include/tr1/cmath (pow(double, double), pow(float, float), pow(long double, long double), pow(_Tp, _Up)): Define. * include/tr1/complex (pow): Do not bring in from namespace std. (pow(const std::complex<_Tp>&, int), pow(const std::complex<_Tp>&, const _Tp&), pow(const _Tp&, const std::complex<_Tp>&), pow(const std::complex<_Tp>&, const std::complex<_Tp>&)): Define. * include/tr1_impl/complex (pow(const std::complex<_Tp>&, const _Up&), pow(const _Tp&, const std::complex<_Up>&), pow(const std::complex<_Tp>&, const std::complex<_Up>&)): Always define. * doc/xml/manual/intro.xml: Add an entry for DR 550. * testsuite/26_numerics/headers/cmath/dr550.cc: New. * testsuite/tr1/8_c_compatibility/cmath/overloads.cc: Adjust. From-SVN: r135955 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6fae3e258df..1c023cfe827 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2008-05-26 Paolo Carlini + + * include/c_global/cmath (pow(float, int), pow(double, int), + pow(long double, int)): Do not define in C++0x mode, per DR 550. + * include/tr1_impl/cmath (pow): Do not bring in unconditionally + from namespace std. + * include/tr1/cmath (pow(double, double), pow(float, float), + pow(long double, long double), pow(_Tp, _Up)): Define. + * include/tr1/complex (pow): Do not bring in from namespace std. + (pow(const std::complex<_Tp>&, int), pow(const std::complex<_Tp>&, + const _Tp&), pow(const _Tp&, const std::complex<_Tp>&), + pow(const std::complex<_Tp>&, const std::complex<_Tp>&)): Define. + * include/tr1_impl/complex (pow(const std::complex<_Tp>&, + const _Up&), pow(const _Tp&, const std::complex<_Up>&), + pow(const std::complex<_Tp>&, const std::complex<_Up>&)): Always + define. + * doc/xml/manual/intro.xml: Add an entry for DR 550. + * testsuite/26_numerics/headers/cmath/dr550.cc: New. + * testsuite/tr1/8_c_compatibility/cmath/overloads.cc: Adjust. + 2008-05-25 Paolo Carlini * include/std/tuple: Ifndef __GXX_EXPERIMENTAL_CXX0X__ just error out. diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 55c48a6d1fc..1f6708dac9a 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -611,6 +611,12 @@ Follow the straightforward proposed resolution. + 550: + What should the return type of pow(float,int) be? + + In C++0x mode, remove the pow(float,int), etc., signatures. + + 586: string inserter not a formatted function diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath index 21e21507b08..dd26db1a718 100644 --- a/libstdc++-v3/include/c_global/cmath +++ b/libstdc++-v3/include/c_global/cmath @@ -367,7 +367,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std) pow(long double __x, long double __y) { return __builtin_powl(__x, __y); } - // DR 550. +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 550. What should the return type of pow(float,int) be? inline double pow(double __x, int __i) { return __builtin_powi(__x, __i); } @@ -379,6 +381,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) inline long double pow(long double __x, int __n) { return __builtin_powil(__x, __n); } +#endif template inline diff --git a/libstdc++-v3/include/tr1/cmath b/libstdc++-v3/include/tr1/cmath index 63e6a2e5fda..a9c5aecf018 100644 --- a/libstdc++-v3/include/tr1/cmath +++ b/libstdc++-v3/include/tr1/cmath @@ -56,6 +56,34 @@ # undef _GLIBCXX_INCLUDE_AS_TR1 #endif +namespace std +{ +namespace tr1 +{ + // DR 550. What should the return type of pow(float,int) be? + // NB: C++0x and TR1 != C++03. + inline double + pow(double __x, double __y) + { return std::pow(__x, __y); } + + inline float + pow(float __x, float __y) + { return std::pow(__x, __y); } + + inline long double + pow(long double __x, long double __y) + { return std::pow(__x, __y); } + + template + inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type + pow(_Tp __x, _Up __y) + { + typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; + return std::pow(__type(__x), __type(__y)); + } +} +} + #include #include #include diff --git a/libstdc++-v3/include/tr1/complex b/libstdc++-v3/include/tr1/complex index 8d14681e955..b571a5982ed 100644 --- a/libstdc++-v3/include/tr1/complex +++ b/libstdc++-v3/include/tr1/complex @@ -75,9 +75,27 @@ namespace tr1 } using std::real; - using std::pow; + + template + inline std::complex<_Tp> + pow(const std::complex<_Tp>& __x, int __n) + { return std::pow(__x, __n); } + + template + inline std::complex<_Tp> + pow(const std::complex<_Tp>& __x, const _Tp& __y) + { return std::pow(__x, __y); } + + template + inline std::complex<_Tp> + pow(const _Tp& __x, const std::complex<_Tp>& __y) + { return std::pow(__x, __y); } + + template + inline std::complex<_Tp> + pow(const std::complex<_Tp>& __x, const std::complex<_Tp>& __y) + { return std::pow(__x, __y); } } } #endif // _GLIBCXX_TR1_COMPLEX - diff --git a/libstdc++-v3/include/tr1_impl/cmath b/libstdc++-v3/include/tr1_impl/cmath index afb05e2aa71..d969a8feada 100644 --- a/libstdc++-v3/include/tr1_impl/cmath +++ b/libstdc++-v3/include/tr1_impl/cmath @@ -763,7 +763,9 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 return nexttoward(__type(__x), __y); } - using std::pow; + // DR 550. What should the return type of pow(float,int) be? + // NB: C++0x and TR1 != C++03. + // using std::pow; inline float remainder(float __x, float __y) diff --git a/libstdc++-v3/include/tr1_impl/complex b/libstdc++-v3/include/tr1_impl/complex index 8b4f97401f6..46560deaa4b 100644 --- a/libstdc++-v3/include/tr1_impl/complex +++ b/libstdc++-v3/include/tr1_impl/complex @@ -301,12 +301,11 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 fabs(const std::complex<_Tp>& __z) { return std::abs(__z); } - + /// Additional overloads [8.1.9]. #if (defined(_GLIBCXX_INCLUDE_AS_CXX0X) \ || (defined(_GLIBCXX_INCLUDE_AS_TR1) \ && !defined(__GXX_EXPERIMENTAL_CXX0X__))) - /// Additional overloads [8.1.9]. template inline typename __gnu_cxx::__promote<_Tp>::__type arg(_Tp __x) @@ -338,6 +337,8 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 real(_Tp __x) { return __x; } +#endif + template inline std::complex::__type> pow(const std::complex<_Tp>& __x, const _Up& __y) @@ -363,7 +364,5 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 std::complex<__type>(__y)); } -#endif - _GLIBCXX_END_NAMESPACE_TR1 } diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/dr550.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/dr550.cc new file mode 100644 index 00000000000..b3a9ce0255d --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/dr550.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// 2008-05-26 Paolo Carlini +// +// 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. + +#include +#include +#include + +// DR 550. What should the return type of pow(float,int) be? +void test01() +{ + bool test __attribute__((unused)) = true; + using __gnu_test::check_ret_type; + + const int i1 = 1; + const float f1 = 1.0f; + const double d1 = 1.0; + const long double ld1 = 1.0l; + + check_ret_type(std::pow(f1, i1)); + VERIFY( std::pow(f1, i1) == std::pow(double(f1), double(i1)) ); + check_ret_type(std::pow(d1, i1)); + check_ret_type(std::pow(ld1, i1)); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/overloads.cc b/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/overloads.cc index e925340081e..fea560fc293 100644 --- a/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/overloads.cc +++ b/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/overloads.cc @@ -206,9 +206,7 @@ void test01() check_ret_type(std::tr1::pow(ld0, d0)); check_ret_type(std::tr1::pow(i0, i0)); check_ret_type(std::tr1::pow(d0, i0)); - // DR 550. - // check_ret_type(std::tr1::pow(f0, i0)); - check_ret_type(std::tr1::pow(f0, i0)); + check_ret_type(std::tr1::pow(f0, i0)); check_ret_type(std::tr1::remainder(d0, d0)); check_ret_type(std::tr1::remainder(d0, f0));