Skip to content

Commit

Permalink
Add more debug capacity validation checks on iteration/size.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 675217344
Change-Id: Idfe8f1c91baa053d42b5f4e2f10cf745943d359c
  • Loading branch information
ezbr authored and copybara-github committed Sep 16, 2024
1 parent ba835d5 commit 820f29f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions absl/container/internal/raw_hash_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -2886,22 +2886,26 @@ class raw_hash_set {
return it;
}
iterator end() ABSL_ATTRIBUTE_LIFETIME_BOUND {
AssertNotDebugCapacity();
return iterator(common().generation_ptr());
}

const_iterator begin() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
return const_cast<raw_hash_set*>(this)->begin();
}
const_iterator end() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
return iterator(common().generation_ptr());
return const_cast<raw_hash_set*>(this)->end();
}
const_iterator cbegin() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
return begin();
}
const_iterator cend() const ABSL_ATTRIBUTE_LIFETIME_BOUND { return end(); }

bool empty() const { return !size(); }
size_t size() const { return common().size(); }
size_t size() const {
AssertNotDebugCapacity();
return common().size();
}
size_t capacity() const {
const size_t cap = common().capacity();
// Compiler complains when using functions in ASSUME so use local variable.
Expand Down
6 changes: 6 additions & 0 deletions absl/container/internal/raw_hash_set_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3696,6 +3696,12 @@ TEST(Table, MovedFromCallsFail) {
EXPECT_DEATH_IF_SUPPORTED(t1.merge(t3), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(IntTable{t1}, "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.begin(), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.end(), "moved-from");
// NOLINTNEXTLINE(bugprone-use-after-move)
EXPECT_DEATH_IF_SUPPORTED(t1.size(), "moved-from");
}
{
ABSL_ATTRIBUTE_UNUSED IntTable t1;
Expand Down

0 comments on commit 820f29f

Please sign in to comment.