Commit 820f29f6 by Evan Brown Committed by Copybara-Service

Add more debug capacity validation checks on iteration/size.

PiperOrigin-RevId: 675217344
Change-Id: Idfe8f1c91baa053d42b5f4e2f10cf745943d359c
parent ba835d56
......@@ -2886,6 +2886,7 @@ class raw_hash_set {
return it;
}
iterator end() ABSL_ATTRIBUTE_LIFETIME_BOUND {
AssertNotDebugCapacity();
return iterator(common().generation_ptr());
}
......@@ -2893,7 +2894,7 @@ class raw_hash_set {
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();
......@@ -2901,7 +2902,10 @@ class raw_hash_set {
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.
......
......@@ -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;
......
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