[multiple changes]
authorPaolo Carlini <paolo@gcc.gnu.org>
Wed, 29 Sep 2010 11:56:34 +0000 (11:56 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Wed, 29 Sep 2010 11:56:34 +0000 (11:56 +0000)
2010-09-29  Paolo Carlini  <paolo.carlini@oracle.com>

* include/Makefile.am: Add debug/forward_list.
* include/Makefile.in: Regenerate.

* testsuite/util/testsuite_container_traits.h (traits_base):
Add has_erase_after and hash_insert_after typedefs.
(traits<forward_list<>>): Adjust.
* testsuite/util/exception/safety.h (erase_point, erase_range,
insert_point): Deal correctly with forward_list.
* include/Makefile.am: Add.

2010-09-29  François Dumont  <francois.cppdevs@free.fr>

* src/debug.cc: Add forward_list specific debug messages.
* include/debug/forward_list: New.
* include/debug/formatter.h: Add debug message ids and before begin
iterator state.
* include/debug/macros.h (__glibcxx_check_insert_after,
__glibcxx_check_insert_range_after, __glibcxx_check_erase_after,
__glibcxx_check_erase_range_after): Add.
* include/debug/safe_iterator.h (_BeforeBeginHelper): Add.
(_Safe_iterator<>::_M_before_dereferenceable,
_Safe_iterator<>::_M_is_before_begin): Add.
(_Safe_iterator<>::_M_dereferenceable, _Safe_iterator<>::_M_is_end,
_Safe_iterator<>::_M_incrementable): Adjust.
* include/std/forward_list: Include debug/forward when _GLIBCXX_DEBUG
defined.
* include/bits/forward_list.h, forward_list.tcc: Put in std::__norm
when debug mode is active.
* testsuite/23_containers/forward_list/capacity/1.cc: Fix to compile
even in debug mode.
* testsuite/23_containers/forward_list/debug/erase_after1.cc,
erase_after2.cc, erase_after3.cc, erase_after4.cc, erase_after5.cc,
insert_after1.cc,erase_after6.cc, erase_after7.cc, insert_after2.cc,
erase_after8.cc, insert_after3.cc, erase_after9.cc: New.

From-SVN: r164717

26 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/Makefile.am
libstdc++-v3/include/Makefile.in
libstdc++-v3/include/bits/forward_list.h
libstdc++-v3/include/bits/forward_list.tcc
libstdc++-v3/include/debug/formatter.h
libstdc++-v3/include/debug/forward_list [new file with mode: 0644]
libstdc++-v3/include/debug/macros.h
libstdc++-v3/include/debug/safe_iterator.h
libstdc++-v3/include/std/forward_list
libstdc++-v3/src/debug.cc
libstdc++-v3/testsuite/23_containers/forward_list/capacity/1.cc
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after3.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after4.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after5.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after6.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after7.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after8.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after9.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after3.cc [new file with mode: 0644]
libstdc++-v3/testsuite/util/exception/safety.h
libstdc++-v3/testsuite/util/testsuite_container_traits.h

index 5bb2125..b2669f1 100644 (file)
@@ -1,3 +1,40 @@
+2010-09-29  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * include/Makefile.am: Add debug/forward_list.
+       * include/Makefile.in: Regenerate.
+
+       * testsuite/util/testsuite_container_traits.h (traits_base):
+       Add has_erase_after and hash_insert_after typedefs.
+       (traits<forward_list<>>): Adjust.
+       * testsuite/util/exception/safety.h (erase_point, erase_range,
+       insert_point): Deal correctly with forward_list.
+       * include/Makefile.am: Add.
+
+2010-09-29  François Dumont  <francois.cppdevs@free.fr>
+
+       * src/debug.cc: Add forward_list specific debug messages.
+       * include/debug/forward_list: New.
+       * include/debug/formatter.h: Add debug message ids and before begin
+       iterator state.
+       * include/debug/macros.h (__glibcxx_check_insert_after,
+       __glibcxx_check_insert_range_after, __glibcxx_check_erase_after,
+       __glibcxx_check_erase_range_after): Add.
+       * include/debug/safe_iterator.h (_BeforeBeginHelper): Add.
+       (_Safe_iterator<>::_M_before_dereferenceable,
+       _Safe_iterator<>::_M_is_before_begin): Add.
+       (_Safe_iterator<>::_M_dereferenceable, _Safe_iterator<>::_M_is_end,
+       _Safe_iterator<>::_M_incrementable): Adjust.
+       * include/std/forward_list: Include debug/forward when _GLIBCXX_DEBUG
+       defined.
+       * include/bits/forward_list.h, forward_list.tcc: Put in std::__norm
+       when debug mode is active.
+       * testsuite/23_containers/forward_list/capacity/1.cc: Fix to compile
+       even in debug mode.
+       * testsuite/23_containers/forward_list/debug/erase_after1.cc,
+       erase_after2.cc, erase_after3.cc, erase_after4.cc, erase_after5.cc,
+       insert_after1.cc,erase_after6.cc, erase_after7.cc, insert_after2.cc,
+       erase_after8.cc, insert_after3.cc, erase_after9.cc: New
+
 2010-09-28  DJ Delorie  <dj@redhat.com>
 
        * libsupc++/hash_bytes.cc (_Hash_bytes): Replace "clength" with
index 460e1ff..3723f9f 100644 (file)
@@ -719,6 +719,7 @@ debug_headers = \
        ${debug_srcdir}/debug.h \
        ${debug_srcdir}/deque \
        ${debug_srcdir}/formatter.h \
+       ${debug_srcdir}/forward_list \
        ${debug_srcdir}/functions.h \
        ${debug_srcdir}/list \
        ${debug_srcdir}/map \
index f8a9718..87f5b8f 100644 (file)
@@ -953,6 +953,7 @@ debug_headers = \
        ${debug_srcdir}/debug.h \
        ${debug_srcdir}/deque \
        ${debug_srcdir}/formatter.h \
+       ${debug_srcdir}/forward_list \
        ${debug_srcdir}/functions.h \
        ${debug_srcdir}/list \
        ${debug_srcdir}/map \
index a76c8a3..5c77f31 100644 (file)
@@ -34,7 +34,7 @@
 #include <memory>
 #include <initializer_list>
 
-_GLIBCXX_BEGIN_NAMESPACE(std)
+_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
   /**
    *  @brief  A helper basic node class for %forward_list.
@@ -1289,6 +1289,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
         forward_list<_Tp, _Alloc>& __ly)
     { __lx.swap(__ly); }
 
-_GLIBCXX_END_NAMESPACE // namespace std
+_GLIBCXX_END_NESTED_NAMESPACE // namespace std
 
 #endif // _FORWARD_LIST_H
index 70453c2..caea059 100644 (file)
@@ -29,7 +29,7 @@
 #ifndef _FORWARD_LIST_TCC
 #define _FORWARD_LIST_TCC 1
 
-_GLIBCXX_BEGIN_NAMESPACE(std)
+_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
 
   template<typename _Tp, typename _Alloc>
     _Fwd_list_base<_Tp, _Alloc>::
@@ -491,7 +491,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
           }
       }
  
-_GLIBCXX_END_NAMESPACE // namespace std
+_GLIBCXX_END_NESTED_NAMESPACE // namespace std
 
 #endif /* _FORWARD_LIST_TCC */
 
index 6945a88..3aa5a8a 100644 (file)
@@ -113,7 +113,11 @@ namespace __gnu_debug
     __msg_output_ostream,
     // istreambuf_iterator
     __msg_deref_istreambuf,
-    __msg_inc_istreambuf
+    __msg_inc_istreambuf,
+    // forward_list
+    __msg_insert_after_end,
+    __msg_erase_after_bad,
+    __msg_valid_range2
   };
 
   class _Error_formatter
@@ -135,6 +139,7 @@ namespace __gnu_debug
       __begin,         // dereferenceable, and at the beginning
       __middle,        // dereferenceable, not at the beginning
       __end,           // past-the-end, may be at beginning if sequence empty
+      __before_begin,  // before begin
       __last_state
     };
 
@@ -234,11 +239,11 @@ namespace __gnu_debug
            _M_variant._M_iterator._M_state = __singular;
          else
            {
-             bool __is_begin = __it._M_is_begin();
-             bool __is_end = __it._M_is_end();
-             if (__is_end)
+             if (__it._M_is_before_begin())
+               _M_variant._M_iterator._M_state = __before_begin;
+             else if (__it._M_is_end())
                _M_variant._M_iterator._M_state = __end;
-             else if (__is_begin)
+             else if (__it._M_is_begin())
                _M_variant._M_iterator._M_state = __begin;
              else
                _M_variant._M_iterator._M_state = __middle;
diff --git a/libstdc++-v3/include/debug/forward_list b/libstdc++-v3/include/debug/forward_list
new file mode 100644 (file)
index 0000000..520ece4
--- /dev/null
@@ -0,0 +1,654 @@
+// <forward_list> -*- C++ -*-
+
+// Copyright (C) 2010 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.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/forward_list
+ *  This file is a GNU debug extension to the Standard C++ Library.
+ */
+
+#ifndef _GLIBCXX_DEBUG_FORWARD_LIST
+#define _GLIBCXX_DEBUG_FORWARD_LIST 1
+
+#pragma GCC system_header
+
+#include <forward_list>
+#include <debug/safe_sequence.h>
+#include <debug/safe_iterator.h>
+
+namespace std
+{
+namespace __debug
+{
+  /// Class std::forward_list with safety/checking/debug instrumentation.
+  template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
+    class forward_list
+    : public _GLIBCXX_STD_D::forward_list<_Tp, _Alloc>,
+      public __gnu_debug::_Safe_sequence<forward_list<_Tp, _Alloc> >
+    {
+      typedef _GLIBCXX_STD_D::forward_list<_Tp, _Alloc> _Base;
+      typedef __gnu_debug::_Safe_sequence<forward_list> _Safe_base;
+
+    public:
+      typedef typename _Base::reference             reference;
+      typedef typename _Base::const_reference       const_reference;
+
+      typedef __gnu_debug::_Safe_iterator<typename _Base::iterator,
+                                         forward_list> iterator;
+      typedef __gnu_debug::_Safe_iterator<typename _Base::const_iterator,
+                                         forward_list> const_iterator;
+
+      typedef typename _Base::size_type             size_type;
+      typedef typename _Base::difference_type       difference_type;
+
+      typedef _Tp                                   value_type;
+      typedef _Alloc                                allocator_type;
+      typedef typename _Base::pointer               pointer;
+      typedef typename _Base::const_pointer         const_pointer;
+
+      // 23.2.3.1 construct/copy/destroy:
+      explicit
+      forward_list(const _Alloc& __al = _Alloc())
+      : _Base(__al) { }
+
+      forward_list(const forward_list& __list, const _Alloc& __al)
+      : _Base(__list, __al)
+      { }
+
+      forward_list(forward_list&& __list, const _Alloc& __al)
+      : _Base(std::move(__list), __al)
+      {
+       this->_M_swap(__list);
+      }
+
+      explicit
+      forward_list(size_type __n)
+      : _Base(__n)
+      { }
+
+      forward_list(size_type __n, const _Tp& __value,
+                   const _Alloc& __al = _Alloc())
+      : _Base(__n, __value, __al)
+      { }
+
+      template<typename _InputIterator>
+        forward_list(_InputIterator __first, _InputIterator __last,
+                     const _Alloc& __al = _Alloc())
+        : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
+                                                                    __last)),
+               __gnu_debug::__base(__last), __al)
+        { }
+
+      forward_list(const forward_list& __list)
+      : _Base(__list)
+      { }
+
+      forward_list(forward_list&& __list)
+      : _Base(std::move(__list)) { }
+
+      forward_list(std::initializer_list<_Tp> __il,
+                   const _Alloc& __al = _Alloc())
+      : _Base(__il, __al)
+      { }
+
+      ~forward_list()
+      { }
+
+      forward_list&
+      operator=(const forward_list& __list)
+      {
+       static_cast<_Base&>(*this) = __list;
+       this->_M_invalidate_all();
+       return *this;
+      }
+
+      forward_list&
+      operator=(forward_list&& __list)
+      {
+       // NB: DR 1204.
+       // NB: DR 675.
+       clear();
+       swap(__list);
+       return *this;
+      }
+
+      forward_list&
+      operator=(std::initializer_list<_Tp> __il)
+      {
+       static_cast<_Base&>(*this) = __il;
+       this->_M_invalidate_all();
+        return *this;
+      }
+
+      template<typename _InputIterator>
+        void
+        assign(_InputIterator __first, _InputIterator __last)
+        {
+         __glibcxx_check_valid_range(__first, __last);
+         _Base::assign(__gnu_debug::__base(__first),
+                       __gnu_debug::__base(__last));
+         this->_M_invalidate_all();
+        }
+
+      void
+      assign(size_type __n, const _Tp& __val)
+      {
+       _Base::assign(__n, __val);
+       this->_M_invalidate_all();
+      }
+
+      void
+      assign(std::initializer_list<_Tp> __il)
+      {
+       _Base::assign(__il);
+       this->_M_invalidate_all();
+      }
+
+      using _Base::get_allocator;
+
+      // iterators:
+
+      iterator
+      before_begin()
+      { return iterator(_Base::before_begin(), this); }
+
+      const_iterator
+      before_begin() const
+      { return const_iterator(_Base::before_begin(), this); }
+
+      iterator
+      begin()
+      { return iterator(_Base::begin(), this); }
+
+      const_iterator
+      begin() const
+      { return const_iterator(_Base::begin(), this); }
+
+      iterator
+      end()
+      { return iterator(_Base::end(), this); }
+
+      const_iterator
+      end() const
+      { return const_iterator(_Base::end(), this); }
+
+      const_iterator
+      cbegin() const
+      { return const_iterator(_Base::cbegin(), this); }
+
+      const_iterator
+      cbefore_begin() const
+      { return const_iterator(_Base::cbefore_begin(), this); }
+
+      const_iterator
+      cend() const
+      { return const_iterator(_Base::cend(), this); }
+
+      using _Base::empty;
+      using _Base::max_size;
+
+      // element access:
+
+      reference
+      front()
+      {
+       __glibcxx_check_nonempty();
+       return _Base::front();
+      }
+
+      const_reference
+      front() const
+      {
+       __glibcxx_check_nonempty();
+       return _Base::front();
+      }
+
+      // modifiers:
+
+      using _Base::emplace_front;
+      using _Base::push_front;
+
+      void
+      pop_front()
+      {
+       __glibcxx_check_nonempty();
+       iterator __victim = begin();
+       __victim._M_invalidate();
+       _Base::pop_front();
+      }
+
+      template<typename... _Args>
+       iterator
+       emplace_after(const_iterator __pos, _Args&&... __args)
+       {
+         __glibcxx_check_insert_after(__pos);
+         return iterator(_Base::emplace_after(__pos.base(),
+                                       std::forward<_Args>(__args)...),
+                         this);
+               }
+
+      iterator
+      insert_after(const_iterator __pos, const _Tp& __val)
+      {
+       __glibcxx_check_insert_after(__pos);
+       return iterator(_Base::insert_after(__pos.base(), __val), this);
+      }
+
+      iterator
+      insert_after(const_iterator __pos, _Tp&& __val)
+      {
+       __glibcxx_check_insert_after(__pos);
+       return iterator(_Base::insert_after(__pos.base(), std::move(__val)),
+                       this);
+      }
+
+      iterator
+      insert_after(const_iterator __pos, size_type __n, const _Tp& __val)
+      {
+       __glibcxx_check_insert_after(__pos);
+       return iterator(_Base::insert_after(__pos.base(), __n, __val),
+                       this);
+      }
+
+      template<typename _InputIterator>
+        iterator
+        insert_after(const_iterator __pos,
+                     _InputIterator __first, _InputIterator __last)
+        {
+         __glibcxx_check_insert_range_after(__pos, __first, __last);
+         return iterator(_Base::insert_after(__pos.base(),
+                                             __gnu_debug::__base(__first),
+                                             __gnu_debug::__base(__last)),
+                         this);
+        }
+
+      iterator
+      insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
+      {
+       __glibcxx_check_insert_after(__pos);
+       return iterator(_Base::insert_after(__pos.base(), __il), this);
+      }
+
+      void
+      erase_after(const_iterator __pos)
+      {
+       __glibcxx_check_erase_after(__pos);
+       const_iterator __victim = __pos;
+       ++__victim;
+       __victim._M_invalidate();
+       _Base::erase_after(__pos.base());
+      }
+
+      void
+      erase_after(const_iterator __pos, const_iterator __last)
+      {
+       __glibcxx_check_erase_range_after(__pos, __last);
+       for (const_iterator __victim = std::next(__pos); __victim != __last; )
+         {
+           const_iterator __old = __victim++;
+           __old._M_invalidate();
+         }
+       _Base::erase_after(__pos.base(), __last.base());
+      }
+
+      void
+      swap(forward_list& __list)
+      {
+       _Base::swap(__list);
+       this->_M_swap(__list);
+      }
+
+      void
+      resize(size_type __sz)
+      {
+       this->_M_detach_singular();
+
+       // if __sz < size(), invalidate all iterators in [begin+__sz, end()
+       iterator __victim = begin();
+       iterator __end = end();
+       for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
+         ++__victim;
+
+       while (__victim != __end)
+         {
+           iterator __real_victim = __victim++;
+           __real_victim._M_invalidate();
+         }
+
+       __try
+         {
+           _Base::resize(__sz);
+         }
+       __catch(...)
+         {
+           this->_M_revalidate_singular();
+           __throw_exception_again;
+          }
+      }
+
+      void
+      resize(size_type __sz, const value_type& __val)
+      {
+       this->_M_detach_singular();
+
+       // if __sz < size(), invalidate all iterators in [begin+__sz, end())
+       iterator __victim = begin();
+       iterator __end = end();
+       for (size_type __i = __sz; __victim != __end && __i > 0; --__i)
+         ++__victim;
+
+       while (__victim != __end)
+         {
+           iterator __real_victim = __victim++;
+           __real_victim._M_invalidate();
+         }
+
+       __try
+         {
+           _Base::resize(__sz, __val);
+         }
+       __catch(...)
+         {
+           this->_M_revalidate_singular();
+           __throw_exception_again;
+          }
+      }
+
+      void
+      clear()
+      {
+       _Base::clear();
+       this->_M_invalidate_all();
+      }
+
+      // 23.2.3.5 forward_list operations:
+    private:
+      void
+      _M_splice_after(const_iterator __pos, forward_list&& __list,
+                     const_iterator __before, const_iterator __last)
+      {
+       for (const_iterator __tmp = std::next(__before); __tmp != __last; )
+         {
+           _GLIBCXX_DEBUG_VERIFY(&__list != this || __tmp != __pos,
+                                  _M_message(__gnu_debug::__msg_splice_overlap)
+                                  ._M_iterator(__tmp, "position")
+                                 ._M_iterator(__before, "before")
+                                 ._M_iterator(__last, "last"));
+           const_iterator __victim = __tmp++;
+           // _GLIBCXX_RESOLVE_LIB_DEFECTS
+           // 250. splicing invalidates iterators
+           this->_M_transfer_iter(__victim);
+         }
+
+       _Base::splice_after(__pos.base(), std::move(__list._M_base()),
+                           __before.base(), __last.base());
+      }
+
+    public:
+      void
+      splice_after(const_iterator __pos, forward_list&& __list)
+      {
+        __glibcxx_check_insert_after(__pos);
+       _GLIBCXX_DEBUG_VERIFY(&__list != this,
+                             _M_message(__gnu_debug::__msg_self_splice)
+                             ._M_sequence(*this, "this"));
+       _M_splice_after(__pos, std::move(__list),
+                       __list.before_begin(), __list.end());
+      }
+
+      void
+      splice_after(const_iterator __pos, forward_list&& __list,
+                  const_iterator __i)
+      {
+       __glibcxx_check_insert_after(__pos);
+       _GLIBCXX_DEBUG_VERIFY(__i._M_before_dereferenceable(),
+                             _M_message(__gnu_debug::__msg_splice_bad)
+                             ._M_iterator(__i, "__i"));
+       _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(&__list),
+                             _M_message(__gnu_debug::__msg_splice_other)
+                             ._M_iterator(__i, "__i")
+                             ._M_sequence(__list, "__list"));
+
+       // _GLIBCXX_RESOLVE_LIB_DEFECTS
+       // 250. splicing invalidates iterators
+       this->_M_transfer_iter(__i);
+       _Base::splice_after(__pos.base(), std::move(__list._M_base()),
+                           __i.base());
+      }
+
+      void
+      splice_after(const_iterator __pos, forward_list&& __list,
+                  const_iterator __before, const_iterator __last)
+      {
+        __glibcxx_check_insert_after(__pos);
+       __glibcxx_check_valid_range(__before, __last);
+       _GLIBCXX_DEBUG_VERIFY(__before._M_attached_to(&__list),
+                             _M_message(__gnu_debug::__msg_splice_other)
+                             ._M_sequence(__list, "list")
+                             ._M_iterator(__before, "before"));
+       _GLIBCXX_DEBUG_VERIFY(__before._M_dereferenceable()
+                             || __before._M_is_before_begin(),
+                             _M_message(__gnu_debug::__msg_valid_range2)
+                             ._M_sequence(__list, "list")
+                             ._M_iterator(__before, "before")
+                             ._M_iterator(__last, "last"));
+       _GLIBCXX_DEBUG_VERIFY(__before != __last,
+                             _M_message(__gnu_debug::__msg_valid_range2)
+                             ._M_sequence(__list, "list")
+                             ._M_iterator(__before, "before")
+                             ._M_iterator(__last, "last"));
+       _M_splice_after(__pos, std::move(__list), __before, __last);
+      }
+
+      void
+      remove(const _Tp& __val)
+      {
+       iterator __x = before_begin();
+       iterator __old = __x++;
+       while (__x.base() != _Base::end())
+         {
+           if (*__x == __val)
+             {
+               erase_after(__old);
+               __x = __old; ++__x;
+             }
+           else
+             __old = __x++;
+         }
+      }
+
+      template<typename _Pred>
+        void
+        remove_if(_Pred __pred)
+       {
+         iterator __x = before_begin();
+         iterator __old = __x++;
+         while (__x.base() != _Base::end())
+           {
+             if (__pred(*__x))
+               {
+                 erase_after(__old);
+                 __x = std::next(__old);
+               }
+             else
+               __old = __x++;
+           }
+       }
+
+      void
+      unique()
+      {
+       iterator __first = begin();
+       iterator __last = end();
+       if (__first == __last)
+         return;
+       iterator __next = __first;
+       while (++__next != __last)
+         {
+           if (*__first == *__next)
+             {
+               erase_after(__first);
+               __next = __first;
+             }
+           else
+             __first = __next;
+         }
+      }
+
+      template<typename _BinPred>
+        void
+        unique(_BinPred __binary_pred)
+       {
+         iterator __first = begin();
+         iterator __last = end();
+         if (__first == __last)
+           return;
+         iterator __next = __first;
+         while (++__next != __last)
+           {
+             if (__binary_pred(*__first, *__next))
+               {
+                 erase_after(__first);
+                 __next = __first;
+               }
+             else
+               __first = __next;
+           }
+       }
+
+      void
+      merge(forward_list&& __list)
+      {
+       if (this != &__list)
+       {
+         __glibcxx_check_sorted(_Base::begin(), _Base::end());
+         __glibcxx_check_sorted(__list._M_base().begin(),
+                                __list._M_base().end());
+         for (iterator __tmp = __list.begin(); __tmp != __list.end();)
+           {
+             iterator __victim = __tmp++;
+             this->_M_transfer_iter(__victim);
+           }
+         _Base::merge(std::move(__list._M_base()));
+       }
+      }
+
+      template<typename _Comp>
+        void
+        merge(forward_list&& __list, _Comp __comp)
+       {
+         if (this != &__list)
+         {
+           __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), __comp);
+           __glibcxx_check_sorted_pred(__list._M_base().begin(),
+                                       __list._M_base().end(), __comp);
+           for (iterator __tmp = __list.begin(); __tmp != __list.end();)
+             {
+               iterator __victim = __tmp++;
+               this->_M_transfer_iter(__victim);
+             }
+           _Base::merge(std::move(__list._M_base()), __comp);
+         }
+       }
+
+      using _Base::sort;
+      using _Base::reverse;
+
+      _Base&
+      _M_base()       { return *this; }
+
+      const _Base&
+      _M_base() const { return *this; }
+
+    private:
+      void
+      _M_invalidate_all()
+      {
+       typedef typename _Base::const_iterator _Base_const_iterator;
+       typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
+       this->_M_invalidate_if(_Not_equal(_M_base().end()));
+      }
+    };
+
+  template<typename _Tp, typename _Alloc>
+    bool
+    operator==(const forward_list<_Tp, _Alloc>& __lx,
+               const forward_list<_Tp, _Alloc>& __ly)
+    { return __lx._M_base() == __ly._M_base(); }
+
+  template<typename _Tp, typename _Alloc>
+    inline bool
+    operator<(const forward_list<_Tp, _Alloc>& __lx,
+              const forward_list<_Tp, _Alloc>& __ly)
+    { return __lx._M_base() < __ly._M_base(); }
+
+  template<typename _Tp, typename _Alloc>
+    inline bool
+    operator!=(const forward_list<_Tp, _Alloc>& __lx,
+               const forward_list<_Tp, _Alloc>& __ly)
+    { return !(__lx == __ly); }
+
+  /// Based on operator<
+  template<typename _Tp, typename _Alloc>
+    inline bool
+    operator>(const forward_list<_Tp, _Alloc>& __lx,
+              const forward_list<_Tp, _Alloc>& __ly)
+    { return (__ly < __lx); }
+
+  /// Based on operator<
+  template<typename _Tp, typename _Alloc>
+    inline bool
+    operator>=(const forward_list<_Tp, _Alloc>& __lx,
+               const forward_list<_Tp, _Alloc>& __ly)
+    { return !(__lx < __ly); }
+
+  /// Based on operator<
+  template<typename _Tp, typename _Alloc>
+    inline bool
+    operator<=(const forward_list<_Tp, _Alloc>& __lx,
+               const forward_list<_Tp, _Alloc>& __ly)
+    { return !(__ly < __lx); }
+
+  /// See std::forward_list::swap().
+  template<typename _Tp, typename _Alloc>
+    inline void
+    swap(forward_list<_Tp, _Alloc>& __lx,
+        forward_list<_Tp, _Alloc>& __ly)
+    { __lx.swap(__ly); }
+
+} // namespace __debug
+} // namespace std
+
+namespace __gnu_debug
+{
+  template<class _Tp, class _Alloc>
+    struct _BeforeBeginHelper<std::__debug::forward_list<_Tp, _Alloc> >
+    {
+      typedef typename forward_list<_Tp, _Alloc>::const_iterator _It;
+
+      static bool
+      _M_Is(_It __it, const forward_list<_Tp, _Alloc>* __seq)
+      { return __it == __seq->before_begin(); }
+    };
+}
+
+#endif
index a56001a..1244612 100644 (file)
@@ -56,10 +56,10 @@ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last),    \
 
 /** Verify that we can insert into *this with the iterator _Position.
  *  Insertion into a container at a specific position requires that
- *  the iterator be nonsingular (i.e., either dereferenceable or
- *  past-the-end) and that it reference the sequence we are inserting
- *  into. Note that this macro is only valid when the container is a
- *  _Safe_sequence and the iterator is a _Safe_iterator.
+ *  the iterator be nonsingular, either dereferenceable or past-the-end,
+ *  and that it reference the sequence we are inserting into. Note that
+ *  this macro is only valid when the container is a_Safe_sequence and
+ *  the iterator is a _Safe_iterator.
 */
 #define __glibcxx_check_insert(_Position)                              \
 _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),                                \
@@ -71,6 +71,20 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                        \
                      ._M_sequence(*this, "this")                       \
                      ._M_iterator(_Position, #_Position))
 
+/** Verify that we can insert into *this after the iterator _Position.
+ *  Insertion into a container after a specific position requires that
+ *  the iterator be nonsingular, either dereferenceable or before-begin,
+ *  and that it reference the sequence we are inserting into. Note that
+ *  this macro is only valid when the container is a_Safe_sequence and
+ *  the iterator is a _Safe_iterator.
+*/
+#define __glibcxx_check_insert_after(_Position)                                \
+__glibcxx_check_insert(_Position);                                     \
+_GLIBCXX_DEBUG_VERIFY(!_Position._M_is_end(),                          \
+                     _M_message(__gnu_debug::__msg_insert_after_end)   \
+                     ._M_sequence(*this, "this")                       \
+                     ._M_iterator(_Position, #_Position))
+
 /** Verify that we can insert the values in the iterator range
  *  [_First, _Last) into *this with the iterator _Position.  Insertion
  *  into a container at a specific position requires that the iterator
@@ -86,14 +100,24 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                      \
 */
 #define __glibcxx_check_insert_range(_Position,_First,_Last)           \
 __glibcxx_check_valid_range(_First,_Last);                             \
-_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(),                                \
-                     _M_message(__gnu_debug::__msg_insert_singular)    \
-                      ._M_sequence(*this, "this")                      \
-                     ._M_iterator(_Position, #_Position));             \
-_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                  \
-                     _M_message(__gnu_debug::__msg_insert_different)   \
-                     ._M_sequence(*this, "this")                       \
-                     ._M_iterator(_Position, #_Position))
+__glibcxx_check_insert(_Position)
+
+/** Verify that we can insert the values in the iterator range
+ *  [_First, _Last) into *this after the iterator _Position.  Insertion
+ *  into a container after a specific position requires that the iterator
+ *  be nonsingular (i.e., either dereferenceable or past-the-end),
+ *  that it reference the sequence we are inserting into, and that the
+ *  iterator range [_First, Last) is a valid (possibly empty)
+ *  range. Note that this macro is only valid when the container is a
+ *  _Safe_sequence and the iterator is a _Safe_iterator.
+ *
+ *  @todo We would like to be able to check for noninterference of
+ *  _Position and the range [_First, _Last), but that can't (in
+ *  general) be done.
+*/
+#define __glibcxx_check_insert_range_after(_Position,_First,_Last)     \
+__glibcxx_check_valid_range(_First,_Last);                             \
+__glibcxx_check_insert_after(_Position)
 
 /** Verify that we can erase the element referenced by the iterator
  * _Position. We can erase the element if the _Position iterator is
@@ -109,6 +133,20 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                      \
                      ._M_sequence(*this, "this")                       \
                      ._M_iterator(_Position, #_Position))
 
+/** Verify that we can erase the element after the iterator
+ * _Position. We can erase the element if the _Position iterator is
+ * before a dereferenceable one and references this sequence.
+*/
+#define __glibcxx_check_erase_after(_Position)                         \
+_GLIBCXX_DEBUG_VERIFY(_Position._M_before_dereferenceable(),           \
+                     _M_message(__gnu_debug::__msg_erase_after_bad)    \
+                     ._M_sequence(*this, "this")                       \
+                     ._M_iterator(_Position, #_Position));             \
+_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this),                  \
+                     _M_message(__gnu_debug::__msg_erase_different)    \
+                     ._M_sequence(*this, "this")                       \
+                     ._M_iterator(_Position, #_Position))
+
 /** Verify that we can erase the elements in the iterator range
  *  [_First, _Last). We can erase the elements if [_First, _Last) is a
  *  valid iterator range within this sequence.
@@ -121,6 +159,36 @@ _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),                 \
                      ._M_iterator(_First, #_First)                     \
                      ._M_iterator(_Last, #_Last))
 
+/** Verify that we can erase the elements in the iterator range
+ *  (_First, _Last). We can erase the elements if (_First, _Last) is a
+ *  valid iterator range within this sequence.
+*/
+#define __glibcxx_check_erase_range_after(_First,_Last)                        \
+_GLIBCXX_DEBUG_VERIFY(_First._M_can_compare(_Last),                    \
+                     _M_message(__gnu_debug::__msg_erase_different)    \
+                     ._M_sequence(*this, "this")                       \
+                     ._M_iterator(_First, #_First)                     \
+                     ._M_iterator(_Last, #_Last));                     \
+_GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this),                     \
+                     _M_message(__gnu_debug::__msg_erase_different)    \
+                     ._M_sequence(*this, "this")                       \
+                     ._M_iterator(_First, #_First));                   \
+_GLIBCXX_DEBUG_VERIFY(_First != _Last,                                 \
+                     _M_message(__gnu_debug::__msg_valid_range2)       \
+                     ._M_sequence(*this, "this")                       \
+                     ._M_iterator(_First, #_First)                     \
+                     ._M_iterator(_Last, #_Last));                     \
+_GLIBCXX_DEBUG_VERIFY(_First._M_incrementable(),                       \
+                     _M_message(__gnu_debug::__msg_valid_range2)       \
+                     ._M_sequence(*this, "this")                       \
+                     ._M_iterator(_First, #_First)                     \
+                     ._M_iterator(_Last, #_Last));                     \
+_GLIBCXX_DEBUG_VERIFY(!_Last._M_is_before_begin(),                     \
+                     _M_message(__gnu_debug::__msg_valid_range2)       \
+                     ._M_sequence(*this, "this")                       \
+                     ._M_iterator(_First, #_First)                     \
+                     ._M_iterator(_Last, #_Last))                      \
+
 // Verify that the subscript _N is less than the container's size.
 #define __glibcxx_check_subscript(_N)                                  \
 _GLIBCXX_DEBUG_VERIFY(_N < this->size(),                               \
index 91b059e..1d47945 100644 (file)
 
 namespace __gnu_debug
 {
+  /** Helper struct to deal with sequence offering a before_begin
+   *  iterator.
+   **/
+  template <typename _Sequence>
+    struct _BeforeBeginHelper
+    {
+      typedef typename _Sequence::const_iterator _It;
+
+      static bool
+      _M_Is(_It __it, const _Sequence* __seq)
+      { return false; }
+    };
+
   /** Iterators that derive from _Safe_iterator_base but that aren't
    *  _Safe_iterators can be determined singular or non-singular via
    *  _Safe_iterator_base.
@@ -343,11 +356,20 @@ namespace __gnu_debug
       /// Is the iterator dereferenceable?
       bool
       _M_dereferenceable() const
-      { return !this->_M_singular() && !_M_is_end(); }
+      { return !this->_M_singular() && !_M_is_end() && !_M_is_before_begin(); }
+
+      /// Is the iterator before a dereferenceable one?
+      bool
+      _M_before_dereferenceable() const
+      {
+       _Self __it = *this;
+       return __it._M_incrementable() && (++__it)._M_dereferenceable();
+      }
 
       /// Is the iterator incrementable?
       bool
-      _M_incrementable() const { return this->_M_dereferenceable(); }
+      _M_incrementable() const
+      { return !this->_M_singular() && !_M_is_end(); }
 
       // Is the iterator decrementable?
       bool
@@ -398,11 +420,16 @@ namespace __gnu_debug
 
       /// Is this iterator equal to the sequence's begin() iterator?
       bool _M_is_begin() const
-      {        return *this == static_cast<const _Sequence*>(_M_sequence)->begin(); }
+      { return *this == _M_get_sequence()->begin(); }
 
       /// Is this iterator equal to the sequence's end() iterator?
       bool _M_is_end() const
-      {        return *this == static_cast<const _Sequence*>(_M_sequence)->end(); }
+      { return *this == _M_get_sequence()->end(); }
+
+      /// Is this iterator equal to the sequence's before_begin() iterator if
+      /// any?
+      bool _M_is_before_begin() const
+      { return _BeforeBeginHelper<_Sequence>::_M_Is(*this, _M_get_sequence()); }
     };
 
   template<typename _IteratorL, typename _IteratorR, typename _Sequence>
index 8b11db7..3222352 100644 (file)
 # include <bits/forward_list.tcc>
 #endif
 
+#ifdef _GLIBCXX_DEBUG
+# include <debug/forward_list>
+#endif
+
 #endif // __GXX_EXPERIMENTAL_CXX0X__
 
 #endif // _GLIBCXX_FORWARD_LIST
index bb0aebe..3deb527 100644 (file)
@@ -1,6 +1,6 @@
 // Debugging mode support code -*- C++ -*-
 
-// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -105,7 +105,12 @@ namespace __gnu_debug
     "attempt to output via an ostream_iterator with no associated stream",
     "attempt to dereference an end-of-stream istreambuf_iterator"
     " (this is a GNU extension)",
-    "attempt to increment an end-of-stream istreambuf_iterator"
+    "attempt to increment an end-of-stream istreambuf_iterator",
+    "attempt to insert into container after an end iterator",
+    "attempt to erase from container after a %2.state; iterator not followed"
+    " by a dereferenceable one",
+    "function requires a valid iterator range (%1.name;, %2.name;)"
+    ", %1.name; shall not be equal to %2.name;"
   };
 
   void
@@ -325,7 +330,8 @@ namespace __gnu_debug
                "singular",
                "dereferenceable (start-of-sequence)",
                "dereferenceable",
-               "past-the-end"
+               "past-the-end",
+               "before begin"
              };
            __formatter->_M_print_word(__state_names[_M_variant.
                                                     _M_iterator._M_state]);
index b9a2ff2..5bb9fb9 100644 (file)
@@ -38,8 +38,14 @@ test01()
   fld.resize(0);
   VERIFY(fld.empty() == true);
 
+#ifndef _GLIBCXX_DEBUG
+  using std::_Fwd_list_node;
+#else
+  using std::_GLIBCXX_STD_D::_Fwd_list_node;
+#endif
+
   VERIFY( (fld.max_size()
-          == std::allocator<std::_Fwd_list_node<double> >().max_size()) );
+          == std::allocator<_Fwd_list_node<double> >().max_size()) );
 }
 
 int
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after1.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after1.cc
new file mode 100644 (file)
index 0000000..f2cd593
--- /dev/null
@@ -0,0 +1,45 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::forward_list<int> fl1{1, 2, 3};
+
+  auto it = fl1.begin();
+  VERIFY( *it == 1 );
+
+  fl1.erase_after(fl1.before_begin());
+
+  VERIFY( *it == 1 );
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after2.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after2.cc
new file mode 100644 (file)
index 0000000..6e24335
--- /dev/null
@@ -0,0 +1,36 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+  fl1.erase_after(fl1.end());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after3.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after3.cc
new file mode 100644 (file)
index 0000000..70a0a34
--- /dev/null
@@ -0,0 +1,36 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1};
+  fl1.erase_after(fl1.begin());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after4.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after4.cc
new file mode 100644 (file)
index 0000000..9e4b3d4
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+  std::forward_list<int> fl2{1, 2, 3};
+
+  fl1.erase_after(fl1.before_begin(), fl2.begin());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after5.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after5.cc
new file mode 100644 (file)
index 0000000..6aabbea
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+  std::forward_list<int> fl2{1, 2, 3};
+
+  fl1.erase_after(fl2.before_begin(), fl2.begin());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after6.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after6.cc
new file mode 100644 (file)
index 0000000..29c418a
--- /dev/null
@@ -0,0 +1,37 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+
+  fl1.erase_after(fl1.before_begin(), fl1.before_begin());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after7.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after7.cc
new file mode 100644 (file)
index 0000000..9390827
--- /dev/null
@@ -0,0 +1,37 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+
+  fl1.erase_after(fl1.end(), fl1.begin());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after8.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after8.cc
new file mode 100644 (file)
index 0000000..77dcb75
--- /dev/null
@@ -0,0 +1,37 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+
+  fl1.erase_after(fl1.begin(), fl1.before_begin());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after9.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/erase_after9.cc
new file mode 100644 (file)
index 0000000..42fe202
--- /dev/null
@@ -0,0 +1,39 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+
+  auto it = fl1.begin();
+  ++it;
+  fl1.erase_after(it, fl1.begin());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after1.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after1.cc
new file mode 100644 (file)
index 0000000..08d49a5
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+  std::forward_list<int> fl2{1, 2, 3};
+
+  fl1.insert_after(fl1.before_begin(), fl2.before_begin(), fl2.end());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after2.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after2.cc
new file mode 100644 (file)
index 0000000..db9fd5e
--- /dev/null
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+  std::forward_list<int> fl2{0};
+
+  fl1.insert_after(fl1.before_begin(), fl2.begin(), fl2.before_begin());
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after3.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/insert_after3.cc
new file mode 100644 (file)
index 0000000..4ad698f
--- /dev/null
@@ -0,0 +1,37 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-debug-mode "" }
+// { dg-do run { xfail *-*-* } }
+
+// Copyright (C) 2010 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 Pred 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 <forward_list>
+
+void
+test01()
+{
+  std::forward_list<int> fl1{1, 2, 3};
+
+  fl1.insert_after(fl1.end(), 4);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
index bc96505..202352d 100644 (file)
@@ -347,8 +347,14 @@ namespace __gnu_test
          _F_erase_range(&container_type::erase) { }
       };
 
-    template<typename _Tp, bool = traits<_Tp>::has_erase::value>
-      struct erase_point : public erase_base<_Tp>
+    template<typename _Tp,
+            bool = traits<_Tp>::has_erase::value,
+            bool = traits<_Tp>::has_erase_after::value>
+      struct erase_point;
+
+    // Specialization for most containers.
+    template<typename _Tp>
+      struct erase_point<_Tp, true, false> : public erase_base<_Tp>
       {
        using erase_base<_Tp>::_F_erase_point;
 
@@ -374,17 +380,51 @@ namespace __gnu_test
        }
       };
 
+    // Specialization for forward_list.
+    template<typename _Tp>
+      struct erase_point<_Tp, false, true> : public erase_base<_Tp>
+      {
+       using erase_base<_Tp>::_F_erase_point;
+
+       void
+       operator()(_Tp& __container)
+       {
+         try
+           {
+             // NB: Should be equivalent to size() member function, but
+             // computed with begin() and end().
+             const size_type sz = std::distance(__container.begin(),
+                                                __container.end());
+
+             // NB: Lowest common denominator: use forward iterator operations.
+             auto i = __container.before_begin();
+             std::advance(i, generate(sz));
+
+             // Makes it easier to think of this as __container.erase(i)
+             (__container.*_F_erase_point)(i);
+           }
+         catch(const __gnu_cxx::forced_error&)
+           { throw; }
+       }
+      };
+
     // Specialization, empty.
     template<typename _Tp>
-      struct erase_point<_Tp, false>
+      struct erase_point<_Tp, false, false>
       {
        void
        operator()(_Tp&) { }
       };
 
 
-    template<typename _Tp, bool = traits<_Tp>::has_erase::value>
-      struct erase_range : public erase_base<_Tp>
+    template<typename _Tp,
+            bool = traits<_Tp>::has_erase::value,
+            bool = traits<_Tp>::has_erase_after::value>
+      struct erase_range;
+
+    // Specialization for most containers.
+    template<typename _Tp>
+      struct erase_range<_Tp, true, false> : public erase_base<_Tp>
       {
        using erase_base<_Tp>::_F_erase_range;
 
@@ -410,9 +450,37 @@ namespace __gnu_test
        }
       };
 
+    // Specialization for forward_list.
+    template<typename _Tp>
+      struct erase_range<_Tp, false, true> : public erase_base<_Tp>
+      {
+       using erase_base<_Tp>::_F_erase_range;
+
+       void
+       operator()(_Tp& __container)
+       {
+         try
+           {
+             const size_type sz = std::distance(__container.begin(),
+                                                __container.end());
+             size_type s1 = generate(sz);
+             size_type s2 = generate(sz);
+             auto i1 = __container.before_begin();
+             auto i2 = __container.before_begin();
+             std::advance(i1, std::min(s1, s2));
+             std::advance(i2, std::max(s1, s2));
+
+             // Makes it easier to think of this as __container.erase(i1, i2).
+             (__container.*_F_erase_range)(i1, i2);
+           }
+         catch(const __gnu_cxx::forced_error&)
+           { throw; }
+       }
+      };
+
     // Specialization, empty.
     template<typename _Tp>
-      struct erase_range<_Tp, false>
+      struct erase_range<_Tp, false, false>
       {
        void
        operator()(_Tp&) { }
@@ -677,8 +745,14 @@ namespace __gnu_test
        insert_base() : _F_insert_point(&container_type::insert) { }
       };
 
-    template<typename _Tp, bool = traits<_Tp>::has_insert::value>
-      struct insert_point : public insert_base<_Tp>
+    template<typename _Tp,
+            bool = traits<_Tp>::has_insert::value,
+            bool = traits<_Tp>::has_insert_after::value>
+      struct insert_point;
+
+    // Specialization for most containers.
+    template<typename _Tp>
+      struct insert_point<_Tp, true, false> : public insert_base<_Tp>
       {
        typedef _Tp                                     container_type;
        typedef typename container_type::value_type     value_type;
@@ -718,9 +792,51 @@ namespace __gnu_test
        }
       };
 
+    // Specialization for forward_list.
+    template<typename _Tp>
+      struct insert_point<_Tp, false, true> : public insert_base<_Tp>
+      {
+       typedef _Tp                                     container_type;
+       typedef typename container_type::value_type     value_type;
+       using insert_base<_Tp>::_F_insert_point;
+
+       void
+       operator()(_Tp& __test)
+       {
+         try
+           {
+             const value_type cv = generate_unique<value_type>();
+             const size_type sz = std::distance(__test.begin(), __test.end());
+             size_type s = generate(sz);
+             auto i = __test.before_begin();
+             std::advance(i, s);
+             (__test.*_F_insert_point)(i, cv);
+           }
+         catch(const __gnu_cxx::forced_error&)
+           { throw; }
+       }
+
+       // Assumes containers start out equivalent.
+       void
+       operator()(_Tp& __control, _Tp& __test)
+       {
+         try
+           {
+             const value_type cv = generate_unique<value_type>();
+             const size_type sz = std::distance(__test.begin(), __test.end());
+             size_type s = generate(sz);
+             auto i = __test.before_begin();
+             std::advance(i, s);
+             (__test.*_F_insert_point)(i, cv);
+           }
+         catch(const __gnu_cxx::forced_error&)
+           { throw; }
+       }
+      };
+
     // Specialization, empty.
     template<typename _Tp>
-      struct insert_point<_Tp, false>
+      struct insert_point<_Tp, false, false>
       {
        void
        operator()(_Tp&) { }
index d6be444..4d8ff99 100644 (file)
@@ -39,8 +39,10 @@ namespace __gnu_test
     typedef std::false_type    is_mapped;
 
     typedef std::false_type    has_erase;
+    typedef std::false_type    has_erase_after;
     typedef std::false_type    has_throwing_erase;
     typedef std::false_type    has_insert;
+    typedef std::false_type    has_insert_after;
     typedef std::false_type    has_push_pop;
     typedef std::false_type    has_size_type_constructor;
   };
@@ -78,8 +80,8 @@ namespace __gnu_test
       typedef std::true_type   is_container;
       typedef std::true_type   is_allocator_aware;
 
-      typedef std::true_type   has_erase;
-      typedef std::true_type   has_insert;
+      typedef std::true_type   has_erase_after;
+      typedef std::true_type   has_insert_after;
       typedef std::true_type   has_push_pop;
       typedef std::true_type   has_size_type_constructor;
     };