diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2009-07-22 12:19:58 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2009-07-22 12:19:58 +0000 |
commit | af4beb4b957395c1eddac112cf14fa4e53d6c414 (patch) | |
tree | 1e61190c3a9a6815bd9ea630167bfc40abe36aa1 | |
parent | 9d0c37619fe75c702cb4892e944290ae0aa21f98 (diff) | |
download | gcc-af4beb4b957395c1eddac112cf14fa4e53d6c414.zip gcc-af4beb4b957395c1eddac112cf14fa4e53d6c414.tar.gz gcc-af4beb4b957395c1eddac112cf14fa4e53d6c414.tar.bz2 |
valarray (valarray<>::operator=(const valarray<>&), [...]): Implement resolution of DR 630, [Ready] in Frankfurt.
2009-07-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/valarray (valarray<>::operator=(const valarray<>&),
valarray<>::operator=(initializer_list<>)): Implement resolution
of DR 630, [Ready] in Frankfurt.
* testsuite/26_numerics/valarray/dr630-1.cc: New.
* testsuite/26_numerics/valarray/dr630-2.cc: Likewise.
* doc/xml/manual/intro.xml: Add an entry for DR 630.
From-SVN: r149929
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/doc/xml/manual/intro.xml | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/std/valarray | 41 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/26_numerics/valarray/dr630-1.cc | 60 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/26_numerics/valarray/dr630-2.cc | 62 |
5 files changed, 172 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 84e1edc..2caf219 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2009-07-22 Paolo Carlini <paolo.carlini@oracle.com> + + * include/std/valarray (valarray<>::operator=(const valarray<>&), + valarray<>::operator=(initializer_list<>)): Implement resolution + of DR 630, [Ready] in Frankfurt. + * testsuite/26_numerics/valarray/dr630-1.cc: New. + * testsuite/26_numerics/valarray/dr630-2.cc: Likewise. + * doc/xml/manual/intro.xml: Add an entry for DR 630. + 2009-07-21 Paolo Carlini <paolo.carlini@oracle.com> * include/std/chrono (duration<>::operator%=, operator%): diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 48d412c..9523195 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -711,6 +711,12 @@ requirements of the license of GCC. <listitem><para>Add the missing modes to fopen_mode. </para></listitem></varlistentry> + <varlistentry><term><ulink url="../ext/lwg-active.html#630">630</ulink>: + <emphasis>arrays of valarray</emphasis> + </term> + <listitem><para>Implement the simple resolution. + </para></listitem></varlistentry> + <varlistentry><term><ulink url="../ext/lwg-defects.html#660">660</ulink>: <emphasis>Missing bitwise operations</emphasis> </term> diff --git a/libstdc++-v3/include/std/valarray b/libstdc++-v3/include/std/valarray index 79d3a16..fa92751 100644 --- a/libstdc++-v3/include/std/valarray +++ b/libstdc++-v3/include/std/valarray @@ -1,7 +1,7 @@ // The template and inlines for the -*- C++ -*- valarray class. // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, -// 2006, 2007, 2009 +// 2006, 2007, 2008, 2009 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -647,7 +647,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template<typename _Tp> inline valarray<_Tp>::valarray(initializer_list<_Tp> __l) - : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size())) + : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size())) { std::__valarray_copy_construct (__l.begin(), __l.end(), _M_data); } #endif @@ -669,8 +669,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std) inline valarray<_Tp>& valarray<_Tp>::operator=(const valarray<_Tp>& __v) { - _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size); - std::__valarray_copy(__v._M_data, _M_size, _M_data); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 630. arrays of valarray. + if (_M_size == __v._M_size) + std::__valarray_copy(__v._M_data, _M_size, _M_data); + else + { + if (_M_data) + { + std::__valarray_destroy_elements(_M_data, _M_data + _M_size); + std::__valarray_release_memory(_M_data); + } + _M_size = __v._M_size; + _M_data = __valarray_get_storage<_Tp>(_M_size); + std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size, + _M_data); + } return *this; } @@ -679,8 +693,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) inline valarray<_Tp>& valarray<_Tp>::operator=(initializer_list<_Tp> __l) { - _GLIBCXX_DEBUG_ASSERT(_M_size == __l.size()); - std::__valarray_copy(__l.begin(), __l.size(), _M_data); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 630. arrays of valarray. + if (_M_size == __l.size()) + std::__valarray_copy(__l.begin(), __l.size(), _M_data); + else + { + if (_M_data) + { + std::__valarray_destroy_elements(_M_data, _M_data + _M_size); + std::__valarray_release_memory(_M_data); + } + _M_size = __l.size(); + _M_data = __valarray_get_storage<_Tp>(_M_size); + std::__valarray_copy_construct(__l.begin(), __l.begin() + _M_size, + _M_data); + } + return *this; } #endif diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/dr630-1.cc b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-1.cc new file mode 100644 index 0000000..9e5d14a --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-1.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2009 Free Software Foundation +// +// 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 <valarray> +#include <testsuite_hooks.h> + +// DR 630. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + valarray<int> v1; + const valarray<int> v2(-1, 10000); + + v1 = v2; + VERIFY( v1.size() == v2.size() ); + VERIFY( (v1 == v2).min() == true ); + + valarray<int> v3(0, 10000); + const valarray<int> v4; + + v3 = v4; + VERIFY( v3.size() == v4.size() ); + VERIFY( v3.size() == 0 ); + + valarray<int> v5(0, 100); + const valarray<int> v6(-1, 10000); + + v5 = v6; + VERIFY( v5.size() == v6.size() ); + VERIFY( (v5 == v6).min() == true ); + + valarray<int> v7(0, 10000); + const valarray<int> v8(-1, 100); + + v7 = v8; + VERIFY( v7.size() == v8.size() ); + VERIFY( (v7 == v8).min() == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/dr630-2.cc b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-2.cc new file mode 100644 index 0000000..70ee812 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-2.cc @@ -0,0 +1,62 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2009 Free Software Foundation +// +// 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 <valarray> +#include <testsuite_hooks.h> + +// DR 630. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + valarray<int> v1; + + v1 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; + VERIFY( v1.size() == 10 ); + VERIFY( v1.min() == -1 ); + VERIFY( v1.max() == -1 ); + + valarray<int> v2(0, 10); + + v2 = { -1, -1, -1, -1, -1 }; + VERIFY( v2.size() == 5 ); + VERIFY( v2.min() == -1 ); + VERIFY( v2.max() == -1 ); + + valarray<int> v3(0, 5); + + v3 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; + VERIFY( v3.size() == 10 ); + VERIFY( v3.min() == -1 ); + VERIFY( v3.max() == -1 ); + + valarray<int> v4(0, 10); + + v4 = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; + VERIFY( v4.size() == 10 ); + VERIFY( v4.min() == -1 ); + VERIFY( v4.max() == -1 ); +} + +int main() +{ + test01(); + return 0; +} |