Hi,
now that Jason implemented list-initialization of complex in mainline,
we can fix this completely in the library. For 4_6-branch I mean to fix
it only in C++03 mode, where we can do work in the body (the constructor
is constexpr in C++0x mode).
Tested x86_64-linux, applied to mainline.
Paolo.
////////////////////
2011-04-28 Paolo Carlini <paolo.carl...@oracle.com>
PR libstdc++/48760
* include/std/complex (complex<float>::complex(float, float),
complex<double>::complex(double, double),
complex<long double>::complex(long double, long double)): Use
list-initialization in C++0x mode, initialize in the body in
C++03 mode.
* testsuite/26_numerics/complex/cons/48760.cc: New.
* testsuite/26_numerics/complex/cons/48760_c++0x.cc: Likewise.
2011-04-28 Paolo Carlini <paolo.carl...@oracle.com>
* include/std/bitset (_Base_bitset(unsigned long long)): Minor
tweak, remove redundant round braces.
Index: include/std/bitset
===================================================================
--- include/std/bitset (revision 173064)
+++ include/std/bitset (working copy)
@@ -80,11 +80,11 @@
#ifdef __GXX_EXPERIMENTAL_CXX0X__
constexpr _Base_bitset(unsigned long long __val)
- : _M_w({ _WordT(__val)
+ : _M_w{ _WordT(__val)
#if __SIZEOF_LONG_LONG__ > __SIZEOF_LONG__
, _WordT(__val >> _GLIBCXX_BITSET_BITS_PER_WORD)
#endif
- }) { }
+ } { }
#else
_Base_bitset(unsigned long __val)
: _M_w()
Index: include/std/complex
===================================================================
--- include/std/complex (revision 173064)
+++ include/std/complex (working copy)
@@ -1,7 +1,7 @@
// The template and inlines for the -*- C++ -*- complex number classes.
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007, 2008, 2009, 2010
+// 2006, 2007, 2008, 2009, 2010, 2011
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -1046,7 +1046,14 @@
_GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
_GLIBCXX_CONSTEXPR complex(float __r = 0.0f, float __i = 0.0f)
- : _M_value(__r + __i * 1.0fi) { }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ : _M_value{ __r, __i } { }
+#else
+ {
+ __real__ _M_value = __r;
+ __imag__ _M_value = __i;
+ }
+#endif
explicit _GLIBCXX_CONSTEXPR complex(const complex<double>&);
explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&);
@@ -1186,7 +1193,14 @@
_GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { }
_GLIBCXX_CONSTEXPR complex(double __r = 0.0, double __i = 0.0)
- : _M_value(__r + __i * 1.0i) { }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ : _M_value{ __r, __i } { }
+#else
+ {
+ __real__ _M_value = __r;
+ __imag__ _M_value = __i;
+ }
+#endif
_GLIBCXX_CONSTEXPR complex(const complex<float>& __z)
: _M_value(__z.__rep()) { }
@@ -1328,7 +1342,14 @@
_GLIBCXX_CONSTEXPR complex(long double __r = 0.0L,
long double __i = 0.0L)
- : _M_value(__r + __i * 1.0Li) { }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ : _M_value{ __r, __i } { }
+#else
+ {
+ __real__ _M_value = __r;
+ __imag__ _M_value = __i;
+ }
+#endif
_GLIBCXX_CONSTEXPR complex(const complex<float>& __z)
: _M_value(__z.__rep()) { }
Index: testsuite/26_numerics/complex/cons/48760.cc
===================================================================
--- testsuite/26_numerics/complex/cons/48760.cc (revision 0)
+++ testsuite/26_numerics/complex/cons/48760.cc (revision 0)
@@ -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
+// <http://www.gnu.org/licenses/>.
+
+#include <complex>
+#include <limits>
+#include <testsuite_hooks.h>
+
+template<typename T>
+ void do_test01()
+ {
+ bool test __attribute__((unused)) = true;
+
+ if (std::numeric_limits<T>::has_quiet_NaN)
+ {
+ std::complex<T> c1(T(0), std::numeric_limits<T>::quiet_NaN());
+ VERIFY( c1.real() == T(0) );
+ VERIFY( std::isnan(c1.imag()) );
+
+ std::complex<T> c2(std::numeric_limits<T>::quiet_NaN(), T(0));
+ VERIFY( std::isnan(c2.real()) );
+ VERIFY( c2.imag() == T(0) );
+
+ std::complex<T> c3(std::numeric_limits<T>::quiet_NaN(),
+ std::numeric_limits<T>::quiet_NaN());
+ VERIFY( std::isnan(c3.real()) );
+ VERIFY( std::isnan(c3.imag()) );
+ }
+ }
+
+// libstdc++/48760
+void test01()
+{
+ do_test01<float>();
+ do_test01<double>();
+ do_test01<long double>();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
Index: testsuite/26_numerics/complex/cons/48760_c++0x.cc
===================================================================
--- testsuite/26_numerics/complex/cons/48760_c++0x.cc (revision 0)
+++ testsuite/26_numerics/complex/cons/48760_c++0x.cc (revision 0)
@@ -0,0 +1,58 @@
+// { 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/>.
+
+#include <complex>
+#include <limits>
+#include <testsuite_hooks.h>
+
+template<typename T>
+ void do_test01()
+ {
+ bool test __attribute__((unused)) = true;
+
+ if (std::numeric_limits<T>::has_quiet_NaN)
+ {
+ std::complex<T> c1(T(0), std::numeric_limits<T>::quiet_NaN());
+ VERIFY( c1.real() == T(0) );
+ VERIFY( std::isnan(c1.imag()) );
+
+ std::complex<T> c2(std::numeric_limits<T>::quiet_NaN(), T(0));
+ VERIFY( std::isnan(c2.real()) );
+ VERIFY( c2.imag() == T(0) );
+
+ std::complex<T> c3(std::numeric_limits<T>::quiet_NaN(),
+ std::numeric_limits<T>::quiet_NaN());
+ VERIFY( std::isnan(c3.real()) );
+ VERIFY( std::isnan(c3.imag()) );
+ }
+ }
+
+// libstdc++/48760
+void test01()
+{
+ do_test01<float>();
+ do_test01<double>();
+ do_test01<long double>();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}