diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2013-06-21 14:23:15 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2013-06-21 14:23:15 +0000 |
commit | b0ad3635b63e6786a8216aa8ec3d4436fa9ae9ac (patch) | |
tree | 627954bccc61124f7e77d0b00ca7e0ff1f8b6893 | |
parent | 927f908bf879a79ec26af82671e2a5b93073a8a2 (diff) | |
download | gcc-b0ad3635b63e6786a8216aa8ec3d4436fa9ae9ac.zip gcc-b0ad3635b63e6786a8216aa8ec3d4436fa9ae9ac.tar.gz gcc-b0ad3635b63e6786a8216aa8ec3d4436fa9ae9ac.tar.bz2 |
re PR libstdc++/57666 (valarray<T>::operator= in c++11 mode does not adapt to size)
2013-06-21 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/57666
* include/std/valarray (valarray<>::operator=(const _Expr<>&)):
Implement correctly C++11 26.6.2.3/1.
* testsuite/26_numerics/valarray/dr630-3.C: New.
From-SVN: r200305
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/std/valarray | 17 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/26_numerics/valarray/dr630-3.C | 37 |
3 files changed, 59 insertions, 2 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4428e94..6a92f61 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2013-06-21 Paolo Carlini <paolo.carlini@oracle.com> + + PR libstdc++/57666 + * include/std/valarray (valarray<>::operator=(const _Expr<>&)): + Implement correctly C++11 26.6.2.3/1. + * testsuite/26_numerics/valarray/dr630-3.C: New. + 2013-06-18 Jonathan Wakely <jwakely.gcc@gmail.com> PR libstdc++/57641 diff --git a/libstdc++-v3/include/std/valarray b/libstdc++-v3/include/std/valarray index 6bee6e0..be96af6 100644 --- a/libstdc++-v3/include/std/valarray +++ b/libstdc++-v3/include/std/valarray @@ -819,8 +819,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline valarray<_Tp>& valarray<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) { - _GLIBCXX_DEBUG_ASSERT(_M_size == __e.size()); - std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data)); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 630. arrays of valarray. + if (_M_size == __e.size()) + std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data)); + else + { + if (_M_data) + { + std::__valarray_destroy_elements(_M_data, _M_data + _M_size); + std::__valarray_release_memory(_M_data); + } + _M_size = __e.size(); + _M_data = __valarray_get_storage<_Tp>(_M_size); + std::__valarray_copy_construct(__e, _M_size, _Array<_Tp>(_M_data)); + } return *this; } diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/dr630-3.C b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-3.C new file mode 100644 index 0000000..d514635 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/dr630-3.C @@ -0,0 +1,37 @@ +// Copyright (C) 2013 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 <valarray> +#include <testsuite_hooks.h> + +// libstdc++/57666 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::valarray<int> a(3), b(3), d1, d2; + d1 = a; + VERIFY( d1.size() == 3 ); + d2 = a + b; + VERIFY( d2.size() == 3 ); +} + +int main() +{ + test01(); + return 0; +} |