Commit b8b4301e by Paolo Carlini

[multiple changes]

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
parent 38df2baf
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> 2010-09-28 DJ Delorie <dj@redhat.com>
* libsupc++/hash_bytes.cc (_Hash_bytes): Replace "clength" with * libsupc++/hash_bytes.cc (_Hash_bytes): Replace "clength" with
......
...@@ -719,6 +719,7 @@ debug_headers = \ ...@@ -719,6 +719,7 @@ debug_headers = \
${debug_srcdir}/debug.h \ ${debug_srcdir}/debug.h \
${debug_srcdir}/deque \ ${debug_srcdir}/deque \
${debug_srcdir}/formatter.h \ ${debug_srcdir}/formatter.h \
${debug_srcdir}/forward_list \
${debug_srcdir}/functions.h \ ${debug_srcdir}/functions.h \
${debug_srcdir}/list \ ${debug_srcdir}/list \
${debug_srcdir}/map \ ${debug_srcdir}/map \
......
...@@ -953,6 +953,7 @@ debug_headers = \ ...@@ -953,6 +953,7 @@ debug_headers = \
${debug_srcdir}/debug.h \ ${debug_srcdir}/debug.h \
${debug_srcdir}/deque \ ${debug_srcdir}/deque \
${debug_srcdir}/formatter.h \ ${debug_srcdir}/formatter.h \
${debug_srcdir}/forward_list \
${debug_srcdir}/functions.h \ ${debug_srcdir}/functions.h \
${debug_srcdir}/list \ ${debug_srcdir}/list \
${debug_srcdir}/map \ ${debug_srcdir}/map \
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <memory> #include <memory>
#include <initializer_list> #include <initializer_list>
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
/** /**
* @brief A helper basic node class for %forward_list. * @brief A helper basic node class for %forward_list.
...@@ -1289,6 +1289,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -1289,6 +1289,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
forward_list<_Tp, _Alloc>& __ly) forward_list<_Tp, _Alloc>& __ly)
{ __lx.swap(__ly); } { __lx.swap(__ly); }
_GLIBCXX_END_NAMESPACE // namespace std _GLIBCXX_END_NESTED_NAMESPACE // namespace std
#endif // _FORWARD_LIST_H #endif // _FORWARD_LIST_H
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#ifndef _FORWARD_LIST_TCC #ifndef _FORWARD_LIST_TCC
#define _FORWARD_LIST_TCC 1 #define _FORWARD_LIST_TCC 1
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
_Fwd_list_base<_Tp, _Alloc>:: _Fwd_list_base<_Tp, _Alloc>::
...@@ -491,7 +491,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -491,7 +491,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
} }
} }
_GLIBCXX_END_NAMESPACE // namespace std _GLIBCXX_END_NESTED_NAMESPACE // namespace std
#endif /* _FORWARD_LIST_TCC */ #endif /* _FORWARD_LIST_TCC */
...@@ -113,7 +113,11 @@ namespace __gnu_debug ...@@ -113,7 +113,11 @@ namespace __gnu_debug
__msg_output_ostream, __msg_output_ostream,
// istreambuf_iterator // istreambuf_iterator
__msg_deref_istreambuf, __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 class _Error_formatter
...@@ -135,6 +139,7 @@ namespace __gnu_debug ...@@ -135,6 +139,7 @@ namespace __gnu_debug
__begin, // dereferenceable, and at the beginning __begin, // dereferenceable, and at the beginning
__middle, // dereferenceable, not at the beginning __middle, // dereferenceable, not at the beginning
__end, // past-the-end, may be at beginning if sequence empty __end, // past-the-end, may be at beginning if sequence empty
__before_begin, // before begin
__last_state __last_state
}; };
...@@ -234,11 +239,11 @@ namespace __gnu_debug ...@@ -234,11 +239,11 @@ namespace __gnu_debug
_M_variant._M_iterator._M_state = __singular; _M_variant._M_iterator._M_state = __singular;
else else
{ {
bool __is_begin = __it._M_is_begin(); if (__it._M_is_before_begin())
bool __is_end = __it._M_is_end(); _M_variant._M_iterator._M_state = __before_begin;
if (__is_end) else if (__it._M_is_end())
_M_variant._M_iterator._M_state = __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; _M_variant._M_iterator._M_state = __begin;
else else
_M_variant._M_iterator._M_state = __middle; _M_variant._M_iterator._M_state = __middle;
......
...@@ -56,10 +56,10 @@ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last), \ ...@@ -56,10 +56,10 @@ _GLIBCXX_DEBUG_VERIFY(__gnu_debug::__valid_range(_First, _Last), \
/** Verify that we can insert into *this with the iterator _Position. /** Verify that we can insert into *this with the iterator _Position.
* Insertion into a container at a specific position requires that * Insertion into a container at a specific position requires that
* the iterator be nonsingular (i.e., either dereferenceable or * the iterator be nonsingular, either dereferenceable or past-the-end,
* past-the-end) and that it reference the sequence we are inserting * and that it reference the sequence we are inserting into. Note that
* into. Note that this macro is only valid when the container is a * this macro is only valid when the container is a_Safe_sequence and
* _Safe_sequence and the iterator is a _Safe_iterator. * the iterator is a _Safe_iterator.
*/ */
#define __glibcxx_check_insert(_Position) \ #define __glibcxx_check_insert(_Position) \
_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \ _GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \
...@@ -71,6 +71,20 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ ...@@ -71,6 +71,20 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
._M_sequence(*this, "this") \ ._M_sequence(*this, "this") \
._M_iterator(_Position, #_Position)) ._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 /** Verify that we can insert the values in the iterator range
* [_First, _Last) into *this with the iterator _Position. Insertion * [_First, _Last) into *this with the iterator _Position. Insertion
* into a container at a specific position requires that the iterator * into a container at a specific position requires that the iterator
...@@ -86,14 +100,24 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ ...@@ -86,14 +100,24 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
*/ */
#define __glibcxx_check_insert_range(_Position,_First,_Last) \ #define __glibcxx_check_insert_range(_Position,_First,_Last) \
__glibcxx_check_valid_range(_First,_Last); \ __glibcxx_check_valid_range(_First,_Last); \
_GLIBCXX_DEBUG_VERIFY(!_Position._M_singular(), \ __glibcxx_check_insert(_Position)
_M_message(__gnu_debug::__msg_insert_singular) \
._M_sequence(*this, "this") \ /** Verify that we can insert the values in the iterator range
._M_iterator(_Position, #_Position)); \ * [_First, _Last) into *this after the iterator _Position. Insertion
_GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ * into a container after a specific position requires that the iterator
_M_message(__gnu_debug::__msg_insert_different) \ * be nonsingular (i.e., either dereferenceable or past-the-end),
._M_sequence(*this, "this") \ * that it reference the sequence we are inserting into, and that the
._M_iterator(_Position, #_Position)) * 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 /** Verify that we can erase the element referenced by the iterator
* _Position. We can erase the element if the _Position iterator is * _Position. We can erase the element if the _Position iterator is
...@@ -109,6 +133,20 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \ ...@@ -109,6 +133,20 @@ _GLIBCXX_DEBUG_VERIFY(_Position._M_attached_to(this), \
._M_sequence(*this, "this") \ ._M_sequence(*this, "this") \
._M_iterator(_Position, #_Position)) ._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 /** Verify that we can erase the elements in the iterator range
* [_First, _Last). We can erase the elements if [_First, _Last) is a * [_First, _Last). We can erase the elements if [_First, _Last) is a
* valid iterator range within this sequence. * valid iterator range within this sequence.
...@@ -121,6 +159,36 @@ _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \ ...@@ -121,6 +159,36 @@ _GLIBCXX_DEBUG_VERIFY(_First._M_attached_to(this), \
._M_iterator(_First, #_First) \ ._M_iterator(_First, #_First) \
._M_iterator(_Last, #_Last)) ._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. // Verify that the subscript _N is less than the container's size.
#define __glibcxx_check_subscript(_N) \ #define __glibcxx_check_subscript(_N) \
_GLIBCXX_DEBUG_VERIFY(_N < this->size(), \ _GLIBCXX_DEBUG_VERIFY(_N < this->size(), \
......
...@@ -40,6 +40,19 @@ ...@@ -40,6 +40,19 @@
namespace __gnu_debug 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 /** Iterators that derive from _Safe_iterator_base but that aren't
* _Safe_iterators can be determined singular or non-singular via * _Safe_iterators can be determined singular or non-singular via
* _Safe_iterator_base. * _Safe_iterator_base.
...@@ -343,11 +356,20 @@ namespace __gnu_debug ...@@ -343,11 +356,20 @@ namespace __gnu_debug
/// Is the iterator dereferenceable? /// Is the iterator dereferenceable?
bool bool
_M_dereferenceable() const _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? /// Is the iterator incrementable?
bool bool
_M_incrementable() const { return this->_M_dereferenceable(); } _M_incrementable() const
{ return !this->_M_singular() && !_M_is_end(); }
// Is the iterator decrementable? // Is the iterator decrementable?
bool bool
...@@ -398,11 +420,16 @@ namespace __gnu_debug ...@@ -398,11 +420,16 @@ namespace __gnu_debug
/// Is this iterator equal to the sequence's begin() iterator? /// Is this iterator equal to the sequence's begin() iterator?
bool _M_is_begin() const 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? /// Is this iterator equal to the sequence's end() iterator?
bool _M_is_end() const 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> template<typename _IteratorL, typename _IteratorR, typename _Sequence>
......
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
# include <bits/forward_list.tcc> # include <bits/forward_list.tcc>
#endif #endif
#ifdef _GLIBCXX_DEBUG
# include <debug/forward_list>
#endif
#endif // __GXX_EXPERIMENTAL_CXX0X__ #endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // _GLIBCXX_FORWARD_LIST #endif // _GLIBCXX_FORWARD_LIST
// Debugging mode support code -*- C++ -*- // 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. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -105,7 +105,12 @@ namespace __gnu_debug ...@@ -105,7 +105,12 @@ namespace __gnu_debug
"attempt to output via an ostream_iterator with no associated stream", "attempt to output via an ostream_iterator with no associated stream",
"attempt to dereference an end-of-stream istreambuf_iterator" "attempt to dereference an end-of-stream istreambuf_iterator"
" (this is a GNU extension)", " (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 void
...@@ -325,7 +330,8 @@ namespace __gnu_debug ...@@ -325,7 +330,8 @@ namespace __gnu_debug
"singular", "singular",
"dereferenceable (start-of-sequence)", "dereferenceable (start-of-sequence)",
"dereferenceable", "dereferenceable",
"past-the-end" "past-the-end",
"before begin"
}; };
__formatter->_M_print_word(__state_names[_M_variant. __formatter->_M_print_word(__state_names[_M_variant.
_M_iterator._M_state]); _M_iterator._M_state]);
......
...@@ -38,8 +38,14 @@ test01() ...@@ -38,8 +38,14 @@ test01()
fld.resize(0); fld.resize(0);
VERIFY(fld.empty() == true); 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() VERIFY( (fld.max_size()
== std::allocator<std::_Fwd_list_node<double> >().max_size()) ); == std::allocator<_Fwd_list_node<double> >().max_size()) );
} }
int int
......
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
// { 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;
}
...@@ -347,8 +347,14 @@ namespace __gnu_test ...@@ -347,8 +347,14 @@ namespace __gnu_test
_F_erase_range(&container_type::erase) { } _F_erase_range(&container_type::erase) { }
}; };
template<typename _Tp, bool = traits<_Tp>::has_erase::value> template<typename _Tp,
struct erase_point : public erase_base<_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; using erase_base<_Tp>::_F_erase_point;
...@@ -374,17 +380,51 @@ namespace __gnu_test ...@@ -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. // Specialization, empty.
template<typename _Tp> template<typename _Tp>
struct erase_point<_Tp, false> struct erase_point<_Tp, false, false>
{ {
void void
operator()(_Tp&) { } operator()(_Tp&) { }
}; };
template<typename _Tp, bool = traits<_Tp>::has_erase::value> template<typename _Tp,
struct erase_range : public erase_base<_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; using erase_base<_Tp>::_F_erase_range;
...@@ -410,9 +450,37 @@ namespace __gnu_test ...@@ -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. // Specialization, empty.
template<typename _Tp> template<typename _Tp>
struct erase_range<_Tp, false> struct erase_range<_Tp, false, false>
{ {
void void
operator()(_Tp&) { } operator()(_Tp&) { }
...@@ -677,8 +745,14 @@ namespace __gnu_test ...@@ -677,8 +745,14 @@ namespace __gnu_test
insert_base() : _F_insert_point(&container_type::insert) { } insert_base() : _F_insert_point(&container_type::insert) { }
}; };
template<typename _Tp, bool = traits<_Tp>::has_insert::value> template<typename _Tp,
struct insert_point : public insert_base<_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 _Tp container_type;
typedef typename container_type::value_type value_type; typedef typename container_type::value_type value_type;
...@@ -718,9 +792,51 @@ namespace __gnu_test ...@@ -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. // Specialization, empty.
template<typename _Tp> template<typename _Tp>
struct insert_point<_Tp, false> struct insert_point<_Tp, false, false>
{ {
void void
operator()(_Tp&) { } operator()(_Tp&) { }
......
...@@ -39,8 +39,10 @@ namespace __gnu_test ...@@ -39,8 +39,10 @@ namespace __gnu_test
typedef std::false_type is_mapped; typedef std::false_type is_mapped;
typedef std::false_type has_erase; 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_throwing_erase;
typedef std::false_type has_insert; 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_push_pop;
typedef std::false_type has_size_type_constructor; typedef std::false_type has_size_type_constructor;
}; };
...@@ -78,8 +80,8 @@ namespace __gnu_test ...@@ -78,8 +80,8 @@ namespace __gnu_test
typedef std::true_type is_container; typedef std::true_type is_container;
typedef std::true_type is_allocator_aware; typedef std::true_type is_allocator_aware;
typedef std::true_type has_erase; typedef std::true_type has_erase_after;
typedef std::true_type has_insert; typedef std::true_type has_insert_after;
typedef std::true_type has_push_pop; typedef std::true_type has_push_pop;
typedef std::true_type has_size_type_constructor; typedef std::true_type has_size_type_constructor;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment