diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index 7a42a56c332..61cc37d16d5 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h @@ -2823,9 +2823,10 @@ class raw_hash_set { // `that` must be left valid. If Hash is std::function, moving it // would create a nullptr functor that cannot be called. // Note: we avoid using exchange for better generated code. - settings_(PolicyTraits::transfer_uses_memcpy() || !that.is_full_soo() - ? std::move(that.common()) - : CommonFields{full_soo_tag_t{}}, + settings_((that.AssertNotDebugCapacity(), + PolicyTraits::transfer_uses_memcpy() || !that.is_full_soo() + ? std::move(that.common()) + : CommonFields{full_soo_tag_t{}}), that.hash_ref(), that.eq_ref(), that.alloc_ref()) { if (!PolicyTraits::transfer_uses_memcpy() && that.is_full_soo()) { transfer(soo_slot(), that.soo_slot()); @@ -2837,6 +2838,7 @@ class raw_hash_set { raw_hash_set(raw_hash_set&& that, const allocator_type& a) : settings_(CommonFields::CreateDefault(), that.hash_ref(), that.eq_ref(), a) { + that.AssertNotDebugCapacity(); if (a == that.alloc_ref()) { swap_common(that); annotate_for_bug_detection_on_move(that); @@ -2863,8 +2865,7 @@ class raw_hash_set { absl::allocator_traits::is_always_equal::value && std::is_nothrow_move_assignable::value && std::is_nothrow_move_assignable::value) { - // TODO(sbenza): We should only use the operations from the noexcept clause - // to make sure we actually adhere to that contract. + that.AssertNotDebugCapacity(); // NOLINTNEXTLINE: not returning *this for performance. return move_assign( std::move(that), diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 1d0af3f7df2..548a8332ec3 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -3715,6 +3715,8 @@ TEST(Table, MovedFromCallsFail) { EXPECT_DEATH_IF_SUPPORTED(t1.end(), "moved-from"); // NOLINTNEXTLINE(bugprone-use-after-move) EXPECT_DEATH_IF_SUPPORTED(t1.size(), "moved-from"); + // NOLINTNEXTLINE(bugprone-use-after-move) + EXPECT_DEATH_IF_SUPPORTED(IntTable{std::move(t1)}, "moved-from"); } { ABSL_ATTRIBUTE_UNUSED IntTable t1;