From 306133e3d42250f24023acc7f435ee2a63db0afe Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Sat, 12 Nov 2011 15:57:03 +0000 Subject: [PATCH] re PR libstdc++/51083 (TR1 [tr.c99.cmath.over] and C++11 [cmplx.over] overloads not constrained) PR libstdc++/51083 * include/ext/type_traits.h (__promote): Only define __type member for integral and floating point types, to prevent math functions participating in overload resolution for other types. (__promote_2, __promote_3, __promote_4): Use __promote in default template argument values, so deduction only succeeds for integral and floating point types. * testsuite/26_numerics/cmath/51083.cc: New. * testsuite/26_numerics/complex/51083.cc: New. * testsuite/tr1/8_c_compatibility/cmath/51083.cc: New. * testsuite/tr1/8_c_compatibility/complex/51083.cc: New. From-SVN: r181321 --- libstdc++-v3/ChangeLog | 14 +++++ libstdc++-v3/include/ext/type_traits.h | 56 +++++++++-------- .../testsuite/26_numerics/cmath/51083.cc | 62 +++++++++++++++++++ .../testsuite/26_numerics/complex/51083.cc | 54 ++++++++++++++++ .../tr1/8_c_compatibility/cmath/51083.cc | 62 +++++++++++++++++++ .../tr1/8_c_compatibility/complex/51083.cc | 54 ++++++++++++++++ 6 files changed, 277 insertions(+), 25 deletions(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/cmath/51083.cc create mode 100644 libstdc++-v3/testsuite/26_numerics/complex/51083.cc create mode 100644 libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/51083.cc create mode 100644 libstdc++-v3/testsuite/tr1/8_c_compatibility/complex/51083.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 826ca4482dc4..22663da3cac8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,17 @@ +2011-11-12 Jonathan Wakely + + PR libstdc++/51083 + * include/ext/type_traits.h (__promote): Only define __type member + for integral and floating point types, to prevent math functions + participating in overload resolution for other types. + (__promote_2, __promote_3, __promote_4): Use __promote in default + template argument values, so deduction only succeeds for integral and + floating point types. + * testsuite/26_numerics/cmath/51083.cc: New. + * testsuite/26_numerics/complex/51083.cc: New. + * testsuite/tr1/8_c_compatibility/cmath/51083.cc: New. + * testsuite/tr1/8_c_compatibility/complex/51083.cc: New. + 2011-11-10 Andrew MacLeod PR middle-end/51038 diff --git a/libstdc++-v3/include/ext/type_traits.h b/libstdc++-v3/include/ext/type_traits.h index 92747268a06f..b0fa36bcec88 100644 --- a/libstdc++-v3/include/ext/type_traits.h +++ b/libstdc++-v3/include/ext/type_traits.h @@ -161,44 +161,50 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __promote { typedef double __type; }; + // No nested __type member for non-integer non-floating point types, + // allows this type to be used for SFINAE to constrain overloads in + // and to only the intended types. template struct __promote<_Tp, false> - { typedef _Tp __type; }; + { }; - template + template<> + struct __promote + { typedef long double __type; }; + + template<> + struct __promote + { typedef double __type; }; + + template<> + struct __promote + { typedef float __type; }; + + template::__type, + typename _Up2 = typename __promote<_Up>::__type> struct __promote_2 { - private: - typedef typename __promote<_Tp>::__type __type1; - typedef typename __promote<_Up>::__type __type2; - - public: - typedef __typeof__(__type1() + __type2()) __type; + typedef __typeof__(_Tp2() + _Up2()) __type; }; - template + template::__type, + typename _Up2 = typename __promote<_Up>::__type, + typename _Vp2 = typename __promote<_Vp>::__type> struct __promote_3 { - private: - typedef typename __promote<_Tp>::__type __type1; - typedef typename __promote<_Up>::__type __type2; - typedef typename __promote<_Vp>::__type __type3; - - public: - typedef __typeof__(__type1() + __type2() + __type3()) __type; + typedef __typeof__(_Tp2() + _Up2() + _Vp2()) __type; }; - template + template::__type, + typename _Up2 = typename __promote<_Up>::__type, + typename _Vp2 = typename __promote<_Vp>::__type, + typename _Wp2 = typename __promote<_Wp>::__type> struct __promote_4 { - private: - typedef typename __promote<_Tp>::__type __type1; - typedef typename __promote<_Up>::__type __type2; - typedef typename __promote<_Vp>::__type __type3; - typedef typename __promote<_Wp>::__type __type4; - - public: - typedef __typeof__(__type1() + __type2() + __type3() + __type4()) __type; + typedef __typeof__(_Tp2() + _Up2() + _Vp2() + _Wp2()) __type; }; _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/26_numerics/cmath/51083.cc b/libstdc++-v3/testsuite/26_numerics/cmath/51083.cc new file mode 100644 index 000000000000..8ba9b10e5d8c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/cmath/51083.cc @@ -0,0 +1,62 @@ +// { 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 +// . + +#include + +namespace a +{ + template class Mat { }; + + template struct Mat2 : Mat { }; + + template + int fdim(Mat) { return 1; } + + template + int floor(Mat, U) { return 1; } + template + int floor(T, Mat) { return 1; } + + template + int fma(Mat, U, V) { return 1; } + template + int fma(T, Mat, V) { return 1; } + template + int fma(T, U, Mat) { return 1; } +} + +int main() +{ + int __attribute__((unused)) i; + + using namespace std; + + a::Mat2 c; + i = fdim(c); + i = floor(c, 0.); + i = floor(0., c); + i = floor(c, 1); + i = floor(1, c); + i = fma(c, 0., 1.); + i = fma(0., c, 1.); + i = fma(0., 1., c); + i = fma(c, 0., 1); + i = fma(0., c, 1); + i = fma(0., 1, c); +} diff --git a/libstdc++-v3/testsuite/26_numerics/complex/51083.cc b/libstdc++-v3/testsuite/26_numerics/complex/51083.cc new file mode 100644 index 000000000000..54e781ba1a03 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/51083.cc @@ -0,0 +1,54 @@ +// { 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 +// . + +#include + +namespace a +{ + template class Mat { }; + + template struct Mat2 : Mat { }; + + template int arg(Mat) { return 1; } + template int conj(Mat) { return 1; } + template int imag(Mat) { return 1; } + template int norm(Mat) { return 1; } + template int proj(Mat) { return 1; } + template int real(Mat) { return 1; } + + template int pow(Mat, U) { return 1; } + template int pow(T, Mat) { return 1; } +} + +int main() +{ + int __attribute__((unused)) i; + + using namespace std; + + a::Mat2< std::complex > c; + i = arg(c); + i = conj(c); + i = imag(c); + i = norm(c); + i = proj(c); + i = real(c); + i = pow(std::complex(), c); + i = pow(c, std::complex()); +} diff --git a/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/51083.cc b/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/51083.cc new file mode 100644 index 000000000000..504305a30437 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/8_c_compatibility/cmath/51083.cc @@ -0,0 +1,62 @@ +// { 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 +// . + +#include + +namespace a +{ + template class Mat { }; + + template struct Mat2 : Mat { }; + + template + int fdim(Mat) { return 1; } + + template + int floor(Mat, U) { return 1; } + template + int floor(T, Mat) { return 1; } + + template + int fma(Mat, U, V) { return 1; } + template + int fma(T, Mat, V) { return 1; } + template + int fma(T, U, Mat) { return 1; } +} + +int main() +{ + int __attribute__((unused)) i; + + using namespace std::tr1; + + a::Mat2 c; + i = fdim(c); + i = floor(c, 0.); + i = floor(0., c); + i = floor(c, 1); + i = floor(1, c); + i = fma(c, 0., 1.); + i = fma(0., c, 1.); + i = fma(0., 1., c); + i = fma(c, 0., 1); + i = fma(0., c, 1); + i = fma(0., 1, c); +} diff --git a/libstdc++-v3/testsuite/tr1/8_c_compatibility/complex/51083.cc b/libstdc++-v3/testsuite/tr1/8_c_compatibility/complex/51083.cc new file mode 100644 index 000000000000..f41914ee91e0 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/8_c_compatibility/complex/51083.cc @@ -0,0 +1,54 @@ +// { 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 +// . + +#include + +namespace a +{ + template class Mat { }; + + template struct Mat2 : Mat { }; + + template int arg(Mat) { return 1; } + template int conj(Mat) { return 1; } + template int imag(Mat) { return 1; } + template int norm(Mat) { return 1; } + template int proj(Mat) { return 1; } + template int real(Mat) { return 1; } + + template int pow(Mat, U) { return 1; } + template int pow(T, Mat) { return 1; } +} + +int main() +{ + int __attribute__((unused)) i; + + using namespace std::tr1; + + a::Mat2< std::complex > c; + i = arg(c); + i = conj(c); + i = imag(c); + i = norm(c); + i = proj(c); + i = real(c); + i = pow(std::complex(), c); + i = pow(c, std::complex()); +}