Re: fix libstdc++/52433

2012-03-08 Thread Paolo Carlini

On 03/08/2012 02:06 AM, Jonathan Wakely wrote:

On 4 March 2012 12:56, Jonathan Wakely wrote:

PR libstdc++/52433
* include/debug/safe_iterator.h (_Safe_iterator): Add move
constructor and move assignment operator.
* testsuite/23_containers/vector/debug/52433.cc: New.

Tested 'make check check-debug' on x86_64 and committed to trunk.  I
plan to fix this for 4.7.1 and 4.6.4 as well

This restores the debug mode checks when moving singular iterators.

Thanks for the good work on this.

By the way, this morning it occurred to me that we should probably also 
have debug-mode checks for self move-assignment (not just in 
_Safe_iterator)?!?


Or I'm missing something?

Thanks,
Paolo.


Re: fix libstdc++/52433

2012-03-08 Thread Jonathan Wakely
On 8 March 2012 10:22, Paolo Carlini wrote:

 By the way, this morning it occurred to me that we should probably also have
 debug-mode checks for self move-assignment (not just in _Safe_iterator)?!?

Yes, nice idea, the library is allowed to assume it doesn't happen,
but we can and should check it in debug mode.


Re: fix libstdc++/52433

2012-03-07 Thread Jonathan Wakely
On 4 March 2012 12:56, Jonathan Wakely wrote:
        PR libstdc++/52433
        * include/debug/safe_iterator.h (_Safe_iterator): Add move
        constructor and move assignment operator.
        * testsuite/23_containers/vector/debug/52433.cc: New.

 Tested 'make check check-debug' on x86_64 and committed to trunk.  I
 plan to fix this for 4.7.1 and 4.6.4 as well

This restores the debug mode checks when moving singular iterators.

Tested x86_64-linux, committed to trunk.
commit 9ada43f026087d440ed6e70d007b51c497d4b790
Author: Jonathan Wakely jwakely@gmail.com
Date:   Wed Mar 7 01:24:45 2012 +

PR libstdc++/52433
* include/debug/safe_iterator.h (_Safe_iterator): Add debug checks
to move constructor and move assignment operator.

diff --git a/libstdc++-v3/include/debug/safe_iterator.h 
b/libstdc++-v3/include/debug/safe_iterator.h
index 65dff55..6bb3cd2 100644
--- a/libstdc++-v3/include/debug/safe_iterator.h
+++ b/libstdc++-v3/include/debug/safe_iterator.h
@@ -1,6 +1,6 @@
 // Safe iterator implementation  -*- C++ -*-
 
-// Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010, 2011
+// Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010, 2011, 2012
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -176,6 +176,11 @@ namespace __gnu_debug
*/
   _Safe_iterator(_Safe_iterator __x) : _M_current()
   {
+   _GLIBCXX_DEBUG_VERIFY(!__x._M_singular()
+ || __x._M_current == _Iterator(),
+ _M_message(__msg_init_copy_singular)
+ ._M_iterator(*this, this)
+ ._M_iterator(__x, other));
std::swap(_M_current, __x._M_current);
this-_M_attach(__x._M_sequence);
__x._M_detach();
@@ -229,6 +234,11 @@ namespace __gnu_debug
   _Safe_iterator
   operator=(_Safe_iterator __x)
   {
+   _GLIBCXX_DEBUG_VERIFY(!__x._M_singular()
+ || __x._M_current == _Iterator(),
+ _M_message(__msg_copy_singular)
+ ._M_iterator(*this, this)
+ ._M_iterator(__x, other));
_M_current = __x._M_current;
_M_attach(__x._M_sequence);
__x._M_detach();


fix libstdc++/52433

2012-03-04 Thread Jonathan Wakely
PR libstdc++/52433
* include/debug/safe_iterator.h (_Safe_iterator): Add move
constructor and move assignment operator.
* testsuite/23_containers/vector/debug/52433.cc: New.

Tested 'make check check-debug' on x86_64 and committed to trunk.  I
plan to fix this for 4.7.1 and 4.6.4 as well
diff --git a/libstdc++-v3/include/debug/safe_iterator.h 
b/libstdc++-v3/include/debug/safe_iterator.h
index e7cfe9c..65dff55 100644
--- a/libstdc++-v3/include/debug/safe_iterator.h
+++ b/libstdc++-v3/include/debug/safe_iterator.h
@@ -169,6 +169,19 @@ namespace __gnu_debug
  ._M_iterator(__x, other));
   }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  /**
+   * @brief Move construction.
+   * @post __x is singular and unattached
+   */
+  _Safe_iterator(_Safe_iterator __x) : _M_current()
+  {
+   std::swap(_M_current, __x._M_current);
+   this-_M_attach(__x._M_sequence);
+   __x._M_detach();
+  }
+#endif
+
   /**
*  @brief Converting constructor from a mutable iterator to a
*  constant iterator.
@@ -208,6 +221,22 @@ namespace __gnu_debug
return *this;
   }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  /**
+   * @brief Move assignment.
+   * @post __x is singular and unattached
+   */
+  _Safe_iterator
+  operator=(_Safe_iterator __x)
+  {
+   _M_current = __x._M_current;
+   _M_attach(__x._M_sequence);
+   __x._M_detach();
+   __x._M_current = _Iterator();
+   return *this;
+  }
+#endif
+
   /**
*  @brief Iterator dereference.
*  @pre iterator is dereferenceable
@@ -422,7 +451,9 @@ namespace __gnu_debug
   /// Is this iterator equal to the sequence's before_begin() iterator if
   /// any?
   bool _M_is_before_begin() const
-  { return _BeforeBeginHelper_Sequence::_M_Is(base(), 
_M_get_sequence()); }
+  {
+   return _BeforeBeginHelper_Sequence::_M_Is(base(), _M_get_sequence());
+  }
 };
 
   templatetypename _IteratorL, typename _IteratorR, typename _Sequence
diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/52433.cc 
b/libstdc++-v3/testsuite/23_containers/vector/debug/52433.cc
new file mode 100644
index 000..f1f5917
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/debug/52433.cc
@@ -0,0 +1,43 @@
+// Copyright (C) 2012 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/.
+//
+// { dg-require-debug-mode  }
+// { dg-options -std=gnu++0x }
+// { dg-do compile }
+
+// PR libstdc++/52433
+
+#include vector
+
+struct X
+{
+std::vectorint::iterator i;
+
+X() = default;
+X(const X) = default;
+X(X) = default;
+X operator=(const X) = default;
+X operator=(X) = default;
+};
+
+X test01()
+{
+X x;
+x = X();
+return x;
+}
+