From af4beb4b957395c1eddac112cf14fa4e53d6c414 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 22 Jul 2009 12:19:58 +0000 Subject: [PATCH] valarray (valarray<>::operator=(const valarray<>&), [...]): Implement resolution of DR 630, [Ready] in Frankfurt. 2009-07-22 Paolo Carlini * 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 --- libstdc++-v3/ChangeLog | 9 +++ libstdc++-v3/doc/xml/manual/intro.xml | 6 ++ libstdc++-v3/include/std/valarray | 41 ++++++++++-- .../testsuite/26_numerics/valarray/dr630-1.cc | 60 ++++++++++++++++++ .../testsuite/26_numerics/valarray/dr630-2.cc | 62 +++++++++++++++++++ 5 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/valarray/dr630-1.cc create mode 100644 libstdc++-v3/testsuite/26_numerics/valarray/dr630-2.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 84e1edc57a88..2caf219164f0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2009-07-22 Paolo Carlini + + * 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 * 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 48d412c8f5a9..9523195e2bad 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. Add the missing modes to fopen_mode. + 630: + arrays of valarray + + Implement the simple resolution. + + 660: Missing bitwise operations diff --git a/libstdc++-v3/include/std/valarray b/libstdc++-v3/include/std/valarray index 79d3a16ecff0..fa92751791de 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 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 000000000000..9e5d14a285ad --- /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 +// . + +#include +#include + +// DR 630. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + valarray v1; + const valarray v2(-1, 10000); + + v1 = v2; + VERIFY( v1.size() == v2.size() ); + VERIFY( (v1 == v2).min() == true ); + + valarray v3(0, 10000); + const valarray v4; + + v3 = v4; + VERIFY( v3.size() == v4.size() ); + VERIFY( v3.size() == 0 ); + + valarray v5(0, 100); + const valarray v6(-1, 10000); + + v5 = v6; + VERIFY( v5.size() == v6.size() ); + VERIFY( (v5 == v6).min() == true ); + + valarray v7(0, 10000); + const valarray 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 000000000000..70ee81243601 --- /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 +// . + +#include +#include + +// DR 630. +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + valarray 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 v2(0, 10); + + v2 = { -1, -1, -1, -1, -1 }; + VERIFY( v2.size() == 5 ); + VERIFY( v2.min() == -1 ); + VERIFY( v2.max() == -1 ); + + valarray 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 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; +}