re PR libstdc++/25896 ([DR 526] hash_map::erase, unordered_map::erase fail if key is inside the table)

2007-02-23  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/25896
	* include/tr1/hashtable (_Hashtable<>::erase(const key_type&)):
	Take care of &_M_extract((*__slot)->_M_v) == &__k.

	* testsuite/tr1/6_containers/unordered_map/erase/1.cc: New.
	* testsuite/tr1/6_containers/unordered_multimap/erase/1.cc: Likewise.
	* testsuite/tr1/6_containers/unordered_multiset/erase/1.cc: Likewise.
	* testsuite/tr1/6_containers/unordered_set/erase/1.cc: Likewise.

From-SVN: r122276
This commit is contained in:
Paolo Carlini 2007-02-23 23:34:18 +00:00 committed by Paolo Carlini
parent bf69f9d223
commit c0c424e4ab
6 changed files with 556 additions and 2 deletions

View File

@ -1,3 +1,14 @@
2007-02-23 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/25896
* include/tr1/hashtable (_Hashtable<>::erase(const key_type&)):
Take care of &_M_extract((*__slot)->_M_v) == &__k.
* testsuite/tr1/6_containers/unordered_map/erase/1.cc: New.
* testsuite/tr1/6_containers/unordered_multimap/erase/1.cc: Likewise.
* testsuite/tr1/6_containers/unordered_multiset/erase/1.cc: Likewise.
* testsuite/tr1/6_containers/unordered_set/erase/1.cc: Likewise.
2007-02-23 Mark Mitchell <mark@codesourcery.com>
* testsuite/27_io/ios_base/sync_with_stdio/1.cc: XFAIL for wrapped

View File

@ -1063,10 +1063,31 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
while (*__slot && !this->_M_compare(__k, __code, *__slot))
__slot = &((*__slot)->_M_next);
_Node** __saved_slot = 0;
while (*__slot && this->_M_compare(__k, __code, *__slot))
{
_Node* __p = *__slot;
*__slot = __p->_M_next;
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 526. Is it undefined if a function in the standard changes
// in parameters?
if (&this->_M_extract((*__slot)->_M_v) != &__k)
{
_Node* __p = *__slot;
*__slot = __p->_M_next;
_M_deallocate_node(__p);
--_M_element_count;
++__result;
}
else
{
__saved_slot = __slot;
__slot = &((*__slot)->_M_next);
}
}
if (__saved_slot)
{
_Node* __p = *__saved_slot;
*__saved_slot = __p->_M_next;
_M_deallocate_node(__p);
--_M_element_count;
++__result;

View File

@ -0,0 +1,131 @@
// 2007-02-22 Paolo Carlini <pcarlini@suse.de>
//
// Copyright (C) 2007 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 2, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 6.3.4.4 Class template unordered_map
#include <tr1/unordered_map>
#include <string>
#include <testsuite_hooks.h>
// In the occasion of libstdc++/25896
void test01()
{
bool test __attribute__((unused)) = true;
typedef std::tr1::unordered_map<std::string, int> Map;
typedef Map::iterator iterator;
typedef Map::const_iterator const_iterator;
typedef Map::value_type value_type;
Map m1;
m1.insert(value_type("because to why", 1));
m1.insert(value_type("the stockholm syndrome", 2));
m1.insert(value_type("a cereous night", 3));
m1.insert(value_type("eeilo", 4));
m1.insert(value_type("protean", 5));
m1.insert(value_type("the way you are when", 6));
m1.insert(value_type("tillsammans", 7));
m1.insert(value_type("umbra/penumbra", 8));
m1.insert(value_type("belonging (no longer mix)", 9));
m1.insert(value_type("one line behind", 10));
VERIFY( m1.size() == 10 );
VERIFY( m1.erase("eeilo") == 1 );
VERIFY( m1.size() == 9 );
iterator it1 = m1.find("eeilo");
VERIFY( it1 == m1.end() );
VERIFY( m1.erase("tillsammans") == 1 );
VERIFY( m1.size() == 8 );
iterator it2 = m1.find("tillsammans");
VERIFY( it2 == m1.end() );
// Must work (see DR 526)
iterator it3 = m1.find("belonging (no longer mix)");
VERIFY( it3 != m1.end() );
VERIFY( m1.erase(it3->first) == 1 );
VERIFY( m1.size() == 7 );
it3 = m1.find("belonging (no longer mix)");
VERIFY( it3 == m1.end() );
VERIFY( !m1.erase("abra") );
VERIFY( m1.size() == 7 );
VERIFY( !m1.erase("eeilo") );
VERIFY( m1.size() == 7 );
VERIFY( m1.erase("because to why") == 1 );
VERIFY( m1.size() == 6 );
iterator it4 = m1.find("because to why");
VERIFY( it4 == m1.end() );
iterator it5 = m1.find("umbra/penumbra");
iterator it6 = m1.find("one line behind");
VERIFY( it5 != m1.end() );
VERIFY( it6 != m1.end() );
VERIFY( m1.find("the stockholm syndrome") != m1.end() );
VERIFY( m1.find("a cereous night") != m1.end() );
VERIFY( m1.find("the way you are when") != m1.end() );
VERIFY( m1.find("a cereous night") != m1.end() );
VERIFY( m1.erase(it5->first) == 1 );
VERIFY( m1.size() == 5 );
it5 = m1.find("umbra/penumbra");
VERIFY( it5 == m1.end() );
VERIFY( m1.erase(it6->first) == 1 );
VERIFY( m1.size() == 4 );
it6 = m1.find("one line behind");
VERIFY( it6 == m1.end() );
iterator it7 = m1.begin();
iterator it8 = it7;
++it8;
iterator it9 = it8;
++it9;
VERIFY( m1.erase(it8->first) == 1 );
VERIFY( m1.size() == 3 );
VERIFY( ++it7 == it9 );
iterator it10 = it9;
++it10;
iterator it11 = it10;
VERIFY( m1.erase(it9->first) == 1 );
VERIFY( m1.size() == 2 );
VERIFY( ++it10 == m1.end() );
VERIFY( m1.erase(m1.begin()) != m1.end() );
VERIFY( m1.size() == 1 );
VERIFY( m1.begin() == it11 );
VERIFY( m1.erase(m1.begin()->first) == 1 );
VERIFY( m1.size() == 0 );
VERIFY( m1.begin() == m1.end() );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,131 @@
// 2007-02-22 Paolo Carlini <pcarlini@suse.de>
//
// Copyright (C) 2007 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 2, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 6.3.4.6 Class template unordered_multimap
#include <tr1/unordered_map>
#include <string>
#include <testsuite_hooks.h>
// In the occasion of libstdc++/25896
void test01()
{
bool test __attribute__((unused)) = true;
typedef std::tr1::unordered_multimap<std::string, int> Mmap;
typedef Mmap::iterator iterator;
typedef Mmap::const_iterator const_iterator;
typedef Mmap::value_type value_type;
Mmap mm1;
mm1.insert(value_type("because to why", 1));
mm1.insert(value_type("the stockholm syndrome", 2));
mm1.insert(value_type("a cereous night", 3));
mm1.insert(value_type("eeilo", 4));
mm1.insert(value_type("protean", 5));
mm1.insert(value_type("the way you are when", 6));
mm1.insert(value_type("tillsammans", 7));
mm1.insert(value_type("umbra/penumbra", 8));
mm1.insert(value_type("belonging (no longer mix)", 9));
mm1.insert(value_type("one line behind", 10));
VERIFY( mm1.size() == 10 );
VERIFY( mm1.erase("eeilo") == 1 );
VERIFY( mm1.size() == 9 );
iterator it1 = mm1.find("eeilo");
VERIFY( it1 == mm1.end() );
VERIFY( mm1.erase("tillsammans") == 1 );
VERIFY( mm1.size() == 8 );
iterator it2 = mm1.find("tillsammans");
VERIFY( it2 == mm1.end() );
// Must work (see DR 526)
iterator it3 = mm1.find("belonging (no longer mix)");
VERIFY( it3 != mm1.end() );
VERIFY( mm1.erase(it3->first) == 1 );
VERIFY( mm1.size() == 7 );
it3 = mm1.find("belonging (no longer mix)");
VERIFY( it3 == mm1.end() );
VERIFY( !mm1.erase("abra") );
VERIFY( mm1.size() == 7 );
VERIFY( !mm1.erase("eeilo") );
VERIFY( mm1.size() == 7 );
VERIFY( mm1.erase("because to why") == 1 );
VERIFY( mm1.size() == 6 );
iterator it4 = mm1.find("because to why");
VERIFY( it4 == mm1.end() );
iterator it5 = mm1.find("umbra/penumbra");
iterator it6 = mm1.find("one line behind");
VERIFY( it5 != mm1.end() );
VERIFY( it6 != mm1.end() );
VERIFY( mm1.find("the stockholm syndrome") != mm1.end() );
VERIFY( mm1.find("a cereous night") != mm1.end() );
VERIFY( mm1.find("the way you are when") != mm1.end() );
VERIFY( mm1.find("a cereous night") != mm1.end() );
VERIFY( mm1.erase(it5->first) == 1 );
VERIFY( mm1.size() == 5 );
it5 = mm1.find("umbra/penumbra");
VERIFY( it5 == mm1.end() );
VERIFY( mm1.erase(it6->first) == 1 );
VERIFY( mm1.size() == 4 );
it6 = mm1.find("one line behind");
VERIFY( it6 == mm1.end() );
iterator it7 = mm1.begin();
iterator it8 = it7;
++it8;
iterator it9 = it8;
++it9;
VERIFY( mm1.erase(it8->first) == 1 );
VERIFY( mm1.size() == 3 );
VERIFY( ++it7 == it9 );
iterator it10 = it9;
++it10;
iterator it11 = it10;
VERIFY( mm1.erase(it9->first) == 1 );
VERIFY( mm1.size() == 2 );
VERIFY( ++it10 == mm1.end() );
VERIFY( mm1.erase(mm1.begin()) != mm1.end() );
VERIFY( mm1.size() == 1 );
VERIFY( mm1.begin() == it11 );
VERIFY( mm1.erase(mm1.begin()->first) == 1 );
VERIFY( mm1.size() == 0 );
VERIFY( mm1.begin() == mm1.end() );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,130 @@
// 2007-02-22 Paolo Carlini <pcarlini@suse.de>
//
// Copyright (C) 2007 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 2, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 6.3.4.5 Class template unordered_multiset
#include <tr1/unordered_set>
#include <string>
#include <testsuite_hooks.h>
// In the occasion of libstdc++/25896
void test01()
{
bool test __attribute__((unused)) = true;
typedef std::tr1::unordered_multiset<std::string> Mset;
typedef Mset::iterator iterator;
typedef Mset::const_iterator const_iterator;
Mset ms1;
ms1.insert("because to why");
ms1.insert("the stockholm syndrome");
ms1.insert("a cereous night");
ms1.insert("eeilo");
ms1.insert("protean");
ms1.insert("the way you are when");
ms1.insert("tillsammans");
ms1.insert("umbra/penumbra");
ms1.insert("belonging (no longer mix)");
ms1.insert("one line behind");
VERIFY( ms1.size() == 10 );
VERIFY( ms1.erase("eeilo") == 1 );
VERIFY( ms1.size() == 9 );
iterator it1 = ms1.find("eeilo");
VERIFY( it1 == ms1.end() );
VERIFY( ms1.erase("tillsammans") == 1 );
VERIFY( ms1.size() == 8 );
iterator it2 = ms1.find("tillsammans");
VERIFY( it2 == ms1.end() );
// Must work (see DR 526)
iterator it3 = ms1.find("belonging (no longer mix)");
VERIFY( it3 != ms1.end() );
VERIFY( ms1.erase(*it3) == 1 );
VERIFY( ms1.size() == 7 );
it3 = ms1.find("belonging (no longer mix)");
VERIFY( it3 == ms1.end() );
VERIFY( !ms1.erase("abra") );
VERIFY( ms1.size() == 7 );
VERIFY( !ms1.erase("eeilo") );
VERIFY( ms1.size() == 7 );
VERIFY( ms1.erase("because to why") == 1 );
VERIFY( ms1.size() == 6 );
iterator it4 = ms1.find("because to why");
VERIFY( it4 == ms1.end() );
iterator it5 = ms1.find("umbra/penumbra");
iterator it6 = ms1.find("one line behind");
VERIFY( it5 != ms1.end() );
VERIFY( it6 != ms1.end() );
VERIFY( ms1.find("the stockholm syndrome") != ms1.end() );
VERIFY( ms1.find("a cereous night") != ms1.end() );
VERIFY( ms1.find("the way you are when") != ms1.end() );
VERIFY( ms1.find("a cereous night") != ms1.end() );
VERIFY( ms1.erase(*it5) == 1 );
VERIFY( ms1.size() == 5 );
it5 = ms1.find("umbra/penumbra");
VERIFY( it5 == ms1.end() );
VERIFY( ms1.erase(*it6) == 1 );
VERIFY( ms1.size() == 4 );
it6 = ms1.find("one line behind");
VERIFY( it6 == ms1.end() );
iterator it7 = ms1.begin();
iterator it8 = it7;
++it8;
iterator it9 = it8;
++it9;
VERIFY( ms1.erase(*it8) == 1 );
VERIFY( ms1.size() == 3 );
VERIFY( ++it7 == it9 );
iterator it10 = it9;
++it10;
iterator it11 = it10;
VERIFY( ms1.erase(*it9) == 1 );
VERIFY( ms1.size() == 2 );
VERIFY( ++it10 == ms1.end() );
VERIFY( ms1.erase(ms1.begin()) != ms1.end() );
VERIFY( ms1.size() == 1 );
VERIFY( ms1.begin() == it11 );
VERIFY( ms1.erase(*ms1.begin()) == 1 );
VERIFY( ms1.size() == 0 );
VERIFY( ms1.begin() == ms1.end() );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,130 @@
// 2007-02-22 Paolo Carlini <pcarlini@suse.de>
//
// Copyright (C) 2007 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 2, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// 6.3.4.3 Class template unordered_set
#include <tr1/unordered_set>
#include <string>
#include <testsuite_hooks.h>
// In the occasion of libstdc++/25896
void test01()
{
bool test __attribute__((unused)) = true;
typedef std::tr1::unordered_set<std::string> Set;
typedef Set::iterator iterator;
typedef Set::const_iterator const_iterator;
Set s1;
s1.insert("because to why");
s1.insert("the stockholm syndrome");
s1.insert("a cereous night");
s1.insert("eeilo");
s1.insert("protean");
s1.insert("the way you are when");
s1.insert("tillsammans");
s1.insert("umbra/penumbra");
s1.insert("belonging (no longer mix)");
s1.insert("one line behind");
VERIFY( s1.size() == 10 );
VERIFY( s1.erase("eeilo") == 1 );
VERIFY( s1.size() == 9 );
iterator it1 = s1.find("eeilo");
VERIFY( it1 == s1.end() );
VERIFY( s1.erase("tillsammans") == 1 );
VERIFY( s1.size() == 8 );
iterator it2 = s1.find("tillsammans");
VERIFY( it2 == s1.end() );
// Must work (see DR 526)
iterator it3 = s1.find("belonging (no longer mix)");
VERIFY( it3 != s1.end() );
VERIFY( s1.erase(*it3) == 1 );
VERIFY( s1.size() == 7 );
it3 = s1.find("belonging (no longer mix)");
VERIFY( it3 == s1.end() );
VERIFY( !s1.erase("abra") );
VERIFY( s1.size() == 7 );
VERIFY( !s1.erase("eeilo") );
VERIFY( s1.size() == 7 );
VERIFY( s1.erase("because to why") == 1 );
VERIFY( s1.size() == 6 );
iterator it4 = s1.find("because to why");
VERIFY( it4 == s1.end() );
iterator it5 = s1.find("umbra/penumbra");
iterator it6 = s1.find("one line behind");
VERIFY( it5 != s1.end() );
VERIFY( it6 != s1.end() );
VERIFY( s1.find("the stockholm syndrome") != s1.end() );
VERIFY( s1.find("a cereous night") != s1.end() );
VERIFY( s1.find("the way you are when") != s1.end() );
VERIFY( s1.find("a cereous night") != s1.end() );
VERIFY( s1.erase(*it5) == 1 );
VERIFY( s1.size() == 5 );
it5 = s1.find("umbra/penumbra");
VERIFY( it5 == s1.end() );
VERIFY( s1.erase(*it6) == 1 );
VERIFY( s1.size() == 4 );
it6 = s1.find("one line behind");
VERIFY( it6 == s1.end() );
iterator it7 = s1.begin();
iterator it8 = it7;
++it8;
iterator it9 = it8;
++it9;
VERIFY( s1.erase(*it8) == 1 );
VERIFY( s1.size() == 3 );
VERIFY( ++it7 == it9 );
iterator it10 = it9;
++it10;
iterator it11 = it10;
VERIFY( s1.erase(*it9) == 1 );
VERIFY( s1.size() == 2 );
VERIFY( ++it10 == s1.end() );
VERIFY( s1.erase(s1.begin()) != s1.end() );
VERIFY( s1.size() == 1 );
VERIFY( s1.begin() == it11 );
VERIFY( s1.erase(*s1.begin()) == 1 );
VERIFY( s1.size() == 0 );
VERIFY( s1.begin() == s1.end() );
}
int main()
{
test01();
return 0;
}