Patchwork [v3] libstdc++/57666

login
register
mail settings
Submitter Paolo Carlini
Date June 21, 2013, 10:05 a.m.
Message ID <51C42572.7080503@oracle.com>
Download mbox | patch
Permalink /patch/253170/
State New
Headers show

Comments

Paolo Carlini - June 21, 2013, 10:05 a.m.
Hi,

looks like we implemented LWG 630 incompletely, not updating:

     valarray<>::operator=(const _Expr<>&)

together with the copy assignment operator. The inconsistency clearly 
shows up eg when we try to assign the result of an arithmetic binary 
operation.

Tested x86_64-linux. Gaby, any issues?

Thanks,
Paolo.

//////////////////
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.

Patch

Index: include/std/valarray
===================================================================
--- include/std/valarray	(revision 200268)
+++ include/std/valarray	(working copy)
@@ -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;
     }
 
Index: testsuite/26_numerics/valarray/dr630-3.C
===================================================================
--- testsuite/26_numerics/valarray/dr630-3.C	(revision 0)
+++ testsuite/26_numerics/valarray/dr630-3.C	(working copy)
@@ -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), d;
+  d = a;
+  VERIFY( d.size() == 3 );
+  d = a + b;
+  VERIFY( d.size() == 3 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}