diff mbox

[v3] PR libstdc++/50529

Message ID 4E8137D9.2010008@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Sept. 27, 2011, 2:41 a.m. UTC
Hi,

pretty straightforward, tested x86_64-linux, committed to mainline.

Thanks,
Paolo.

///////////////////
2011-09-26  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/50529
	* include/bits/vector.tcc (vector<>::erase(iterator, iterator)):
	Fix to do nothing if the range is empty.
	* include/bits/stl_bvector.h: Likewise.
	* include/bits/deque.tcc: Likewise.
	* include/debug/vector: Adjust.
	* include/debug/deque: Likewise.
	* testsuite/23_containers/vector/modifiers/erase/50529.cc: New.
	* testsuite/23_containers/deque/modifiers/erase/50529.cc: Likewise.
	* testsuite/23_containers/deque/modifiers/erase/3.cc: Adjust.
diff mbox

Patch

Index: include/debug/vector
===================================================================
--- include/debug/vector	(revision 179226)
+++ include/debug/vector	(working copy)
@@ -499,11 +499,16 @@ 
 	// 151. can't currently clear() empty container
 	__glibcxx_check_erase_range(__first, __last);
 
-	difference_type __offset = __first.base() - _Base::begin();
-	_Base_iterator __res = _Base::erase(__first.base(),
-						      __last.base());
-	this->_M_invalidate_after_nth(__offset);
-	return iterator(__res, this);
+	if (__first != __last)
+	  {
+	    difference_type __offset = __first.base() - _Base::begin();
+	    _Base_iterator __res = _Base::erase(__first.base(),
+						__last.base());
+	    this->_M_invalidate_after_nth(__offset);
+	    return iterator(__res, this);
+	  }
+	else
+	  return __first;
       }
 
       void
Index: include/debug/deque
===================================================================
--- include/debug/deque	(revision 179226)
+++ include/debug/deque	(working copy)
@@ -464,7 +464,11 @@ 
 	// _GLIBCXX_RESOLVE_LIB_DEFECTS
 	// 151. can't currently clear() empty container
 	__glibcxx_check_erase_range(__first, __last);
-        if (__first.base() == _Base::begin() || __last.base() == _Base::end())
+
+	if (__first == __last)
+	  return __first;
+        else if (__first.base() == _Base::begin()
+		 || __last.base() == _Base::end())
 	  {
 	    this->_M_detach_singular();
 	    for (_Base_iterator __position = __first.base();
Index: include/bits/vector.tcc
===================================================================
--- include/bits/vector.tcc	(revision 179225)
+++ include/bits/vector.tcc	(working copy)
@@ -147,9 +147,12 @@ 
     vector<_Tp, _Alloc>::
     erase(iterator __first, iterator __last)
     {
-      if (__last != end())
-	_GLIBCXX_MOVE3(__last, end(), __first);
-      _M_erase_at_end(__first.base() + (end() - __last));
+      if (__first != __last)
+	{
+	  if (__last != end())
+	    _GLIBCXX_MOVE3(__last, end(), __first);
+	  _M_erase_at_end(__first.base() + (end() - __last));
+	}
       return __first;
     }
 
Index: include/bits/deque.tcc
===================================================================
--- include/bits/deque.tcc	(revision 179225)
+++ include/bits/deque.tcc	(working copy)
@@ -218,7 +218,9 @@ 
     deque<_Tp, _Alloc>::
     erase(iterator __first, iterator __last)
     {
-      if (__first == begin() && __last == end())
+      if (__first == __last)
+	return __first;
+      else if (__first == begin() && __last == end())
 	{
 	  clear();
 	  return end();
Index: include/bits/stl_bvector.h
===================================================================
--- include/bits/stl_bvector.h	(revision 179225)
+++ include/bits/stl_bvector.h	(working copy)
@@ -838,7 +838,8 @@ 
     iterator
     erase(iterator __first, iterator __last)
     {
-      _M_erase_at_end(std::copy(__last, end(), __first));
+      if (__first != __last)
+	_M_erase_at_end(std::copy(__last, end(), __first));
       return __first;
     }
 
Index: testsuite/23_containers/vector/modifiers/erase/50529.cc
===================================================================
--- testsuite/23_containers/vector/modifiers/erase/50529.cc	(revision 0)
+++ testsuite/23_containers/vector/modifiers/erase/50529.cc	(revision 0)
@@ -0,0 +1,38 @@ 
+// { dg-options "-std=gnu++0x" }
+
+// 2011-09-26  Paolo Carlini  <paolo.carlini@oracle.com>
+
+// 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 <vector>
+#include <testsuite_rvalref.h>
+
+// libstdc++/50529
+void test01()
+{
+  std::vector<__gnu_test::rvalstruct> v(10);
+
+  for (auto it = v.begin(); it != v.end(); ++it)
+    v.erase(it, it);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
Index: testsuite/23_containers/deque/modifiers/erase/3.cc
===================================================================
--- testsuite/23_containers/deque/modifiers/erase/3.cc	(revision 179225)
+++ testsuite/23_containers/deque/modifiers/erase/3.cc	(working copy)
@@ -1,4 +1,4 @@ 
-// Copyright (C) 2007, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2009, 2010, 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
@@ -31,7 +31,9 @@ 
   
   x.erase(x.begin() + elm_strt, x.begin() + elm_end);
   
-  const size_t min_num_cpy = std::min(elm_strt, num_elm - elm_end);
+  const size_t min_num_cpy
+    = elm_strt == elm_end ? 0 : std::min(elm_strt, num_elm - elm_end);
+
   VERIFY( assignment_operator::count() == min_num_cpy );
 }
 
Index: testsuite/23_containers/deque/modifiers/erase/50529.cc
===================================================================
--- testsuite/23_containers/deque/modifiers/erase/50529.cc	(revision 0)
+++ testsuite/23_containers/deque/modifiers/erase/50529.cc	(revision 0)
@@ -0,0 +1,38 @@ 
+// { dg-options "-std=gnu++0x" }
+
+// 2011-09-26  Paolo Carlini  <paolo.carlini@oracle.com>
+
+// 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 <deque>
+#include <testsuite_rvalref.h>
+
+// libstdc++/50529
+void test01()
+{
+  std::deque<__gnu_test::rvalstruct> d(10);
+
+  for (auto it = d.begin(); it != d.end(); ++it)
+    d.erase(it, it);
+}
+
+int main()
+{
+  test01();
+  return 0;
+}