Skip to content

Commit 0bc0e9a

Browse files
ezbrcopybara-github
authored andcommitted
Add more debug capacity validation checks on merge/swap.
PiperOrigin-RevId: 673403995 Change-Id: I62d8bb37d4538c340783fb55e5a00694e932b6d1
1 parent 67d1260 commit 0bc0e9a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

absl/container/internal/raw_hash_set.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,8 @@ class raw_hash_set {
32133213
// If the element already exists in `this`, it is left unmodified in `src`.
32143214
template <typename H, typename E>
32153215
void merge(raw_hash_set<Policy, H, E, Alloc>& src) { // NOLINT
3216+
AssertNotDebugCapacity();
3217+
src.AssertNotDebugCapacity();
32163218
assert(this != &src);
32173219
// Returns whether insertion took place.
32183220
const auto insert_slot = [this](slot_type* src_slot) {
@@ -3263,6 +3265,8 @@ class raw_hash_set {
32633265
IsNoThrowSwappable<hasher>() && IsNoThrowSwappable<key_equal>() &&
32643266
IsNoThrowSwappable<allocator_type>(
32653267
typename AllocTraits::propagate_on_container_swap{})) {
3268+
AssertNotDebugCapacity();
3269+
that.AssertNotDebugCapacity();
32663270
using std::swap;
32673271
swap_common(that);
32683272
swap(hash_ref(), that.hash_ref());

absl/container/internal/raw_hash_set_test.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3685,11 +3685,15 @@ TEST(Table, MovedFromCallsFail) {
36853685
}
36863686

36873687
{
3688-
ABSL_ATTRIBUTE_UNUSED IntTable t1, t2;
3688+
ABSL_ATTRIBUTE_UNUSED IntTable t1, t2, t3;
36893689
t1.insert(1);
36903690
t2 = std::move(t1);
36913691
// NOLINTNEXTLINE(bugprone-use-after-move)
36923692
EXPECT_DEATH_IF_SUPPORTED(t1.contains(1), "moved-from");
3693+
// NOLINTNEXTLINE(bugprone-use-after-move)
3694+
EXPECT_DEATH_IF_SUPPORTED(t1.swap(t3), "moved-from");
3695+
// NOLINTNEXTLINE(bugprone-use-after-move)
3696+
EXPECT_DEATH_IF_SUPPORTED(t1.merge(t3), "moved-from");
36933697
}
36943698
{
36953699
ABSL_ATTRIBUTE_UNUSED IntTable t1;

0 commit comments

Comments
 (0)