Commit 0bc0e9a0 by Evan Brown Committed by Copybara-Service

Add more debug capacity validation checks on merge/swap.

PiperOrigin-RevId: 673403995
Change-Id: I62d8bb37d4538c340783fb55e5a00694e932b6d1
parent 67d12608
......@@ -3213,6 +3213,8 @@ class raw_hash_set {
// If the element already exists in `this`, it is left unmodified in `src`.
template <typename H, typename E>
void merge(raw_hash_set<Policy, H, E, Alloc>& src) { // NOLINT
AssertNotDebugCapacity();
src.AssertNotDebugCapacity();
assert(this != &src);
// Returns whether insertion took place.
const auto insert_slot = [this](slot_type* src_slot) {
......@@ -3263,6 +3265,8 @@ class raw_hash_set {
IsNoThrowSwappable<hasher>() && IsNoThrowSwappable<key_equal>() &&
IsNoThrowSwappable<allocator_type>(
typename AllocTraits::propagate_on_container_swap{})) {
AssertNotDebugCapacity();
that.AssertNotDebugCapacity();
using std::swap;
swap_common(that);
swap(hash_ref(), that.hash_ref());
......
......@@ -3685,11 +3685,15 @@ TEST(Table, MovedFromCallsFail) {
}
{
ABSL_ATTRIBUTE_UNUSED IntTable t1, t2;
ABSL_ATTRIBUTE_UNUSED IntTable t1, t2, t3;
t1.insert(1);
t2 = std::move(t1);
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.contains(1), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.swap(t3), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.merge(t3), "moved-from");
}
{
ABSL_ATTRIBUTE_UNUSED IntTable t1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment