From d075e3bd441193d2e72f393bd72f47683c7a3e86 Mon Sep 17 00:00:00 2001 From: jakub Date: Thu, 19 Jan 2012 10:46:31 +0000 Subject: [PATCH] PR libstdc++/51845 * include/bits/hashtable.h (_Hashtable<>::erase(const_iterator, const_iterator)): Also update _M_buckets[__n_bkt] if __is_bucket_begin. * testsuite/23_containers/unordered_multimap/erase/51845-multimap.cc: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183300 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 9 +++ libstdc++-v3/include/bits/hashtable.h | 2 +- .../unordered_multimap/erase/51845-multimap.cc | 72 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/51845-multimap.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f805fd90c07..fa3523b5392 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2012-01-19 Jakub Jelinek + + PR libstdc++/51845 + * include/bits/hashtable.h + (_Hashtable<>::erase(const_iterator, const_iterator)): Also update + _M_buckets[__n_bkt] if __is_bucket_begin. + * testsuite/23_containers/unordered_multimap/erase/51845-multimap.cc: + New test. + 2012-01-18 Benjamin Kosnik * acinclude (GLIBCXX_CONFIGURE_DOCBOOK): Fix quoting. diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index c2ffae24cb6..d4f2aedfccd 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -1544,7 +1544,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __bkt = __n_bkt; } - if (__n && __n_bkt != __bkt) + if (__n && (__n_bkt != __bkt || __is_bucket_begin)) _M_buckets[__n_bkt] = __prev_n; __prev_n->_M_nxt = __n; return iterator(__n); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/51845-multimap.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/51845-multimap.cc new file mode 100644 index 00000000000..450fb6faadf --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/erase/51845-multimap.cc @@ -0,0 +1,72 @@ +// { dg-options "-std=gnu++0x" } + +// 2012-01-19 Jakub Jelinek +// +// Copyright (C) 2012 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +// libstdc++/51845 +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::unordered_multimap Mmap; + typedef Mmap::iterator iterator; + typedef Mmap::const_iterator const_iterator; + typedef Mmap::value_type value_type; + + Mmap mm1; + + mm1.insert(value_type(11135, 1)); + mm1.insert(value_type(11135, 17082)); + mm1.insert(value_type(9644, 24135)); + mm1.insert(value_type(9644, 9644)); + mm1.insert(value_type(13984, 19841)); + mm1.insert(value_type(9644, 1982)); + mm1.insert(value_type(13984, 1945)); + mm1.insert(value_type(7, 1982)); + mm1.insert(value_type(7, 1945)); + VERIFY( mm1.size() == 9 ); + + iterator it1 = mm1.begin(); + ++it1; + iterator it2 = it1; + ++it2; + ++it2; + iterator it3 = mm1.erase(it1, it2); + VERIFY( mm1.size() == 7 ); + VERIFY( it3 == it2 ); + VERIFY( *it3 == *it2 ); + + const_iterator it4 = mm1.begin(); + ++it4; + const_iterator it5 = it4; + ++it5; + const_iterator it6 = mm1.erase(it4); + VERIFY( mm1.size() == 6 ); + VERIFY( it6 == it5 ); + VERIFY( *it6 == *it5 ); +} + +int main() +{ + test01(); + return 0; +} -- 2.11.0