Skip to content

Commit

Permalink
Mark destroyItem() as noexcept
Browse files Browse the repository at this point in the history
Summary:
F14Node{Map,Set} doesn't require `is_nothrow_destructible<value_type>`.  `clear()` and the destructor are both marked `noexcept`, so they will both terminate if the destructor throws. But `erase()` is not marked `noexcept`, so when the destructor throws during `erase()` the value is left in the map. This could be problematic if the value is half destroyed, or if `eraseInto()` is used.

This diff fixes the problem by marking `destroyItem()` as `noexcept`, so `std::terminate` is called whenever the value destructor throws.

Reviewed By: nbronson

Differential Revision: D20604276

fbshipit-source-id: c52c932d78d6ed61368985a749adf77c27a5a0de
  • Loading branch information
terrelln authored and facebook-github-bot committed Mar 26, 2020
1 parent 5b4eed6 commit 8fcf46a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions folly/container/detail/F14Policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class ValueContainerPolicy : public BasePolicy<
}
}

void destroyItem(Item& item) {
void destroyItem(Item& item) noexcept {
Alloc& a = this->alloc();
auto ptr = std::addressof(item);
AllocTraits::destroy(a, ptr);
Expand Down Expand Up @@ -876,7 +876,7 @@ class NodeContainerPolicy
prefetchAddr(std::addressof(*item));
}

void destroyItem(Item& item) {
void destroyItem(Item& item) noexcept {
if (item != nullptr) {
Alloc& a = this->alloc();
AllocTraits::destroy(a, std::addressof(*item));
Expand Down Expand Up @@ -1252,7 +1252,7 @@ class VectorContainerPolicy : public BasePolicy<
prefetchAddr(std::addressof(values_[item]));
}

void destroyItem(Item&) {}
void destroyItem(Item&) noexcept {}

template <typename T>
std::enable_if_t<std::is_nothrow_move_constructible<T>::value>
Expand Down

0 comments on commit 8fcf46a

Please sign in to comment.