diff options
author | Evan Brown <ezb@google.com> | 2022-11-09 11:40:57 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-11-09 11:41:51 -0800 |
commit | 8cfc1500f894c07995abf25c2ad31f38982432cf (patch) | |
tree | 53aba92699b115a7e26af87e9a1f3a88557891dd /absl/container/internal/raw_hash_set_test.cc | |
parent | 66bfca85c825a0c53254fa7f7787784099395d69 (diff) |
Improve error messages when comparing swisstable iterators.
We check for comparisons of swisstable iterators from different heap allocations, which can indicate either iterators from different containers or that there was a rehash between when the iterators were initialized.
PiperOrigin-RevId: 487304602
Change-Id: I5c596c5ea07948d66e048f99937f9032a630344f
Diffstat (limited to 'absl/container/internal/raw_hash_set_test.cc')
-rw-r--r-- | absl/container/internal/raw_hash_set_test.cc | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 6478d3fc..daa32814 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -2082,13 +2082,29 @@ TEST(TableDeathTest, IteratorInvalidAssertsEqualityOperator) { ASSERT_NE(iter2, t.end()); t.erase(iter1); // Extra simple "regexp" as regexp support is highly varied across platforms. - const char* const kDeathMessage = - "Invalid operation on iterator. The element might have .*been erased or " + const char* const kErasedDeathMessage = + "Invalid iterator comparison. The element might have .*been erased or " "the table might have rehashed."; - EXPECT_DEATH_IF_SUPPORTED(void(iter1 == iter2), kDeathMessage); - EXPECT_DEATH_IF_SUPPORTED(void(iter2 != iter1), kDeathMessage); + EXPECT_DEATH_IF_SUPPORTED(void(iter1 == iter2), kErasedDeathMessage); + EXPECT_DEATH_IF_SUPPORTED(void(iter2 != iter1), kErasedDeathMessage); t.erase(iter2); - EXPECT_DEATH_IF_SUPPORTED(void(iter1 == iter2), kDeathMessage); + EXPECT_DEATH_IF_SUPPORTED(void(iter1 == iter2), kErasedDeathMessage); + + IntTable t1, t2; + t1.insert(0); + t2.insert(0); + iter1 = t1.begin(); + iter2 = t2.begin(); + const char* const kContainerDiffDeathMessage = + "Invalid iterator comparison. The iterators may be from different " + ".*containers or the container might have rehashed."; + EXPECT_DEATH_IF_SUPPORTED(void(iter1 == iter2), kContainerDiffDeathMessage); + EXPECT_DEATH_IF_SUPPORTED(void(iter2 == iter1), kContainerDiffDeathMessage); + + for (int i = 0; i < 10; ++i) t1.insert(i); + // There should have been a rehash in t1. + EXPECT_DEATH_IF_SUPPORTED(void(iter1 == t1.begin()), + kContainerDiffDeathMessage); } #if defined(ABSL_INTERNAL_HASHTABLEZ_SAMPLE) |