From 7b7c9ec3558ae51bb4fc3c1a499ddf988cee0086 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 16 Nov 2015 16:42:16 +0000 Subject: [PATCH] LWG#2156 loosened the requirements on unordered containers 'rehash' calls. Add tests to make sure we meet these requirements. Since we met the stricter ones, no code change needed to meet the looser ones. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@253223 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/std/containers/unord/unord.map/rehash.pass.cpp | 12 ++++++++++++ .../containers/unord/unord.multimap/rehash.pass.cpp | 12 ++++++++++++ .../containers/unord/unord.multiset/rehash.pass.cpp | 12 ++++++++++++ test/std/containers/unord/unord.set/rehash.pass.cpp | 12 ++++++++++++ www/cxx1z_status.html | 2 +- 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/test/std/containers/unord/unord.map/rehash.pass.cpp b/test/std/containers/unord/unord.map/rehash.pass.cpp index 84ece235..e1a882c6 100644 --- a/test/std/containers/unord/unord.map/rehash.pass.cpp +++ b/test/std/containers/unord/unord.map/rehash.pass.cpp @@ -21,6 +21,12 @@ #include "min_allocator.h" +template +void rehash_postcondition(const C& c, size_t n) +{ + assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); +} + template void test(const C& c) { @@ -49,13 +55,16 @@ int main() test(c); assert(c.bucket_count() >= 5); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 5); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } @@ -77,13 +86,16 @@ int main() test(c); assert(c.bucket_count() >= 5); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 5); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } diff --git a/test/std/containers/unord/unord.multimap/rehash.pass.cpp b/test/std/containers/unord/unord.multimap/rehash.pass.cpp index 1d992085..d36dc42e 100644 --- a/test/std/containers/unord/unord.multimap/rehash.pass.cpp +++ b/test/std/containers/unord/unord.multimap/rehash.pass.cpp @@ -22,6 +22,12 @@ #include "min_allocator.h" +template +void rehash_postcondition(const C& c, size_t n) +{ + assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); +} + template void test(const C& c) { @@ -77,13 +83,16 @@ int main() test(c); assert(c.bucket_count() >= 7); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 7); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } @@ -105,13 +114,16 @@ int main() test(c); assert(c.bucket_count() >= 7); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 7); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } diff --git a/test/std/containers/unord/unord.multiset/rehash.pass.cpp b/test/std/containers/unord/unord.multiset/rehash.pass.cpp index bc8d461c..5c7c6aa8 100644 --- a/test/std/containers/unord/unord.multiset/rehash.pass.cpp +++ b/test/std/containers/unord/unord.multiset/rehash.pass.cpp @@ -20,6 +20,12 @@ #include "min_allocator.h" +template +void rehash_postcondition(const C& c, size_t n) +{ + assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); +} + template void test(const C& c) { @@ -48,13 +54,16 @@ int main() test(c); assert(c.bucket_count() >= 7); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 7); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } @@ -76,13 +85,16 @@ int main() test(c); assert(c.bucket_count() >= 7); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 7); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } diff --git a/test/std/containers/unord/unord.set/rehash.pass.cpp b/test/std/containers/unord/unord.set/rehash.pass.cpp index 30fffa56..e28c25dc 100644 --- a/test/std/containers/unord/unord.set/rehash.pass.cpp +++ b/test/std/containers/unord/unord.set/rehash.pass.cpp @@ -20,6 +20,12 @@ #include "min_allocator.h" +template +void rehash_postcondition(const C& c, size_t n) +{ + assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n); +} + template void test(const C& c) { @@ -48,13 +54,16 @@ int main() test(c); assert(c.bucket_count() >= 5); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 5); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } @@ -76,13 +85,16 @@ int main() test(c); assert(c.bucket_count() >= 5); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 5); test(c); c.max_load_factor(2); c.rehash(3); + rehash_postcondition(c, 3); assert(c.bucket_count() == 3); test(c); c.rehash(31); + rehash_postcondition(c, 31); assert(c.bucket_count() == 31); test(c); } diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 7d8238f3..67a334f5 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -154,7 +154,7 @@ 2119Missing hash specializations for extended integer typesKona 2127Move-construction with raw_storage_iteratorKonaComplete 2133Attitude to overloaded comma for iteratorsKonaComplete - 2156Unordered containers' reserve(n) reserves for n-1 elementsKona + 2156Unordered containers' reserve(n) reserves for n-1 elementsKonaComplete 2218Unclear how containers use allocator_traits::construct()Kona 2219INVOKE-ing a pointer to member with a reference_wrapper as the object expressionKona 2224Ambiguous status of access to non-live objectsKonaComplete