Commit 3ebc5866 authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

check invariant during swap

Summary:
Container swap is not allowed to fall back to allocation + move
when allocators are not equal, which makes swap undefined in that case.
FOLLY_SAFE_CHECK it.  For zero-size allocators this check will be optimized
away at compile time.

Reviewed By: yfeldblum

Differential Revision: D8209358

fbshipit-source-id: 6555f102c51c97f1e1ecfebd0597c532849184b5
parent 091165ea
......@@ -951,6 +951,15 @@ class F14Table : public Policy {
}
void swap(F14Table& rhs) noexcept(kSwapIsNoexcept) {
// If propagate_on_container_swap is false and allocators are
// not equal, the only way to accomplish a swap would be to do
// dynamic allocation and then move (or swap) each contained value.
// AllocatorAwareContainer-s are not supposed to attempt this, but
// rather are supposed to have undefined behavior in that case.
FOLLY_SAFE_CHECK(
AllocTraits::propagate_on_container_swap::value ||
kAllocIsAlwaysEqual || this->alloc() == rhs.alloc(),
"swap is undefined for unequal non-propagating allocators");
this->swapPolicy(rhs);
swapContents(rhs);
}
......
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