diff --git a/include/boost/unordered/detail/table.hpp b/include/boost/unordered/detail/table.hpp index edbc3773..4d47ee67 100644 --- a/include/boost/unordered/detail/table.hpp +++ b/include/boost/unordered/detail/table.hpp @@ -406,9 +406,8 @@ namespace boost { namespace unordered_detail { template inline void hash_table::create_for_insert(std::size_t size) { - // TODO: Write a test to detect this bug: - if(size > this->bucket_count_) - this->bucket_count_ = this->min_buckets_for_size(size); + std::size_t min_buckets = this->min_buckets_for_size(size); + if(min_buckets > this->bucket_count_) this->bucket_count_ = min_buckets; this->create_buckets(); this->init_buckets(); } diff --git a/test/unordered/constructor_tests.cpp b/test/unordered/constructor_tests.cpp index d5475b1f..0702e4e6 100644 --- a/test/unordered/constructor_tests.cpp +++ b/test/unordered/constructor_tests.cpp @@ -250,6 +250,19 @@ void constructor_tests2(T*, test::random_generator const& generator = test::defa test::check_equivalent_keys(x); test::check_equivalent_keys(y); } + + std::cerr<<"Construct 9\n"; + { + test::random_values v(100, generator); + T x(50); + BOOST_TEST(x.bucket_count() >= 50); + x.max_load_factor(10); + BOOST_TEST(x.bucket_count() >= 50); + x.insert(v.begin(), v.end()); + BOOST_TEST(x.bucket_count() >= 50); + test::check_container(x, v); + test::check_equivalent_keys(x); + } } template