diff --git a/folly/container/test/heap_vector_types_test.cpp b/folly/container/test/heap_vector_types_test.cpp index ef98bc07a76..3ecb8507517 100644 --- a/folly/container/test/heap_vector_types_test.cpp +++ b/folly/container/test/heap_vector_types_test.cpp @@ -171,8 +171,12 @@ TEST(HeapVectorTypes, SimpleSetTest) { EXPECT_TRUE(s == s2); auto it = s2.lower_bound(32); - if (*it == 32) { - s2.erase(it); + if (it != s2.end()) { + if (*it == 32) { + s2.erase(it); + } else { + s2.erase(32); + } it = s2.lower_bound(32); } check_invariant(s2);