Hi
I just prefer to make the tests implementation-agnostic using reserve.
I check that without the patch to initiate the hashtable with 11
buckets I reproduce the failures and that with this patch it is fine.
PR libstdc++/90277
* testsuite/23_containers/unordered_multiset/insert/24061-multiset.cc
(test01): Reserve for number of insertions to avoid rehash during test.
* testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc
(test01): Likewise.
* testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc
(test01): Likewise.
(test02): Likewise.
(test03): Likewise.
I plan to commit it this evening if not told otherwise.
François
On 5/6/19 3:04 PM, redi at gcc dot gnu.org wrote:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90277
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to François Dumont from comment #3)
As stated in my message this patch can be consider as a fix for this PR as
it reserve buckets for 11 buckets so iterators are not invalidated during
execution of the tests. You shouldn't have anymore failures, do you ?
But maybe you would prefer to make those tests independent of this
implementation detail. I'll do that too.
I think it's OK to rely on the detail as long as the tests make that explicit.
A comment saying that they assume there's no rehashing would be OK, even better
would be to use VERIFY to assert that the count doesn't change. If we make the
tests actually verify there's no rehashing, then it's OK to assume no hashing
:-)
Currently it's just a silent assumption, which isn't even true any more.
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc
index 717e9208e4a..1f7a590267e 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/24061-multimap.cc
@@ -32,7 +32,8 @@ void test01()
typedef Mmap::value_type value_type;
Mmap mm1;
-
+ mm1.reserve(3);
+
iterator it1 = mm1.insert(mm1.begin(),
value_type("all the love in the world", 1));
VERIFY( mm1.size() == 1 );
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/hint.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/hint.cc
index a71a6a9539a..c38afc57438 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/hint.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/hint.cc
@@ -29,6 +29,7 @@ void test01()
typedef typename Map::value_type Pair;
Map m;
+ m.reserve(3);
auto it1 = m.insert(Pair(0, 0));
VERIFY( it1 != m.end() );
@@ -58,6 +59,7 @@ void test02()
typedef typename Map::value_type Pair;
Map m;
+ m.reserve(5);
auto it1 = m.insert(Pair(0, 0));
auto it2 = m.insert(it1, Pair(1, 0));
@@ -89,6 +91,7 @@ void test03()
typedef typename Map::value_type Pair;
Map m;
+ m.reserve(3);
auto it1 = m.insert(Pair(0, 0));
VERIFY( it1 != m.end() );
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/24061-multiset.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/24061-multiset.cc
index 04833a67188..0c1029f27ff 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/24061-multiset.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/24061-multiset.cc
@@ -31,6 +31,7 @@ void test01()
typedef Mset::const_iterator const_iterator;
Mset ms1;
+ ms1.reserve(3);
iterator it1 = ms1.insert(ms1.begin(), "all the love in the world");
VERIFY( ms1.size() == 1 );