Upstream-Status: Inappropriate [Backport] From 838560450136f202dc9170f2ad3eec80b41e0381 Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 29 Apr 2011 23:19:59 +0000 Subject: [PATCH 199/200] 2011-04-29 Paolo Carlini PR libstdc++/48760 * include/std/complex (complex::complex(float, float), complex::complex(double, double), complex::complex(long double, long double)): Initialize in the body in C++03 mode (no fix in C++0x mode). * testsuite/26_numerics/complex/cons/48760.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@173195 138bc75d-0d04-0410-961f-82ee72b054a4 index d36eddc..aa6e81d 100644 --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -1046,7 +1046,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { } _GLIBCXX_CONSTEXPR complex(float __r = 0.0f, float __i = 0.0f) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // The list-initialization extension to __complex__ types is + // not available in GCC 4.6. Thus libstdc++/48760 cannot be + // fixed in C++0x mode, unfortunately. : _M_value(__r + __i * 1.0fi) { } +#else + { + __real__ _M_value = __r; + __imag__ _M_value = __i; + } +#endif explicit _GLIBCXX_CONSTEXPR complex(const complex&); explicit _GLIBCXX_CONSTEXPR complex(const complex&); @@ -1186,7 +1196,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { } _GLIBCXX_CONSTEXPR complex(double __r = 0.0, double __i = 0.0) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // The list-initialization extension to __complex__ types is + // not available in GCC 4.6. Thus libstdc++/48760 cannot be + // fixed in C++0x mode, unfortunately. : _M_value(__r + __i * 1.0i) { } +#else + { + __real__ _M_value = __r; + __imag__ _M_value = __i; + } +#endif _GLIBCXX_CONSTEXPR complex(const complex& __z) : _M_value(__z.__rep()) { } @@ -1328,7 +1348,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_CONSTEXPR complex(long double __r = 0.0L, long double __i = 0.0L) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + // The list-initialization extension to __complex__ types is + // not available in GCC 4.6. Thus libstdc++/48760 cannot be + // fixed in C++0x mode, unfortunately. : _M_value(__r + __i * 1.0Li) { } +#else + { + __real__ _M_value = __r; + __imag__ _M_value = __i; + } +#endif _GLIBCXX_CONSTEXPR complex(const complex& __z) : _M_value(__z.__rep()) { } diff --git a/libstdc++-v3/testsuite/26_numerics/complex/cons/48760.cc b/libstdc++-v3/testsuite/26_numerics/complex/cons/48760.cc new file mode 100644 index 0000000..0201cc7 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/cons/48760.cc @@ -0,0 +1,56 @@ +// 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 +#include +#include + +template + void do_test01() + { + bool test __attribute__((unused)) = true; + + if (std::numeric_limits::has_quiet_NaN) + { + std::complex c1(T(0), std::numeric_limits::quiet_NaN()); + VERIFY( c1.real() == T(0) ); + VERIFY( std::isnan(c1.imag()) ); + + std::complex c2(std::numeric_limits::quiet_NaN(), T(0)); + VERIFY( std::isnan(c2.real()) ); + VERIFY( c2.imag() == T(0) ); + + std::complex c3(std::numeric_limits::quiet_NaN(), + std::numeric_limits::quiet_NaN()); + VERIFY( std::isnan(c3.real()) ); + VERIFY( std::isnan(c3.imag()) ); + } + } + +// libstdc++/48760 +void test01() +{ + do_test01(); + do_test01(); + do_test01(); +} + +int main() +{ + test01(); + return 0; +} -- 1.7.0.4