You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
std::vector, when resizing, will only use move if it is declared nothrow.
absl's InlinedVector uses move operations for resizing, regardless.
This means that if a resize operation calls the move constructor and it throws, we end up with a situation where the vector is only partially moved to its new location. Moving the data back might also throw, and we end up with an inconsistent InlinedVector.
InlinedVector should either use copy constructors in that case, or insist that the move operator is declared nothrow.
The text was updated successfully, but these errors were encountered:
On a slightly pedantic note, an InlinedVector of objects in maybe-moved-from states is still in a valid state, so this technically satisfies basic exception safety -- but I agree it's not a nice thing to do.
I think this is a two step solution -- we declare that InlinedVector only supports T with nothrow move operators in the short term.
In the long term, Abseil's stance on throwing moves constructors is essentially that move constructors can only throw if the allocator can throw -- we're stricter than the standard on thsi point of view. So as I ramp up the exception-safety test suite we can advise the move constructor to be noexcept if the allocator is noexcept and use the current algorithm, and fall back to copying only if the allocator throws and T has a throwing move constructor.
std::vector, when resizing, will only use move if it is declared nothrow.
absl's InlinedVector uses move operations for resizing, regardless.
This means that if a resize operation calls the move constructor and it throws, we end up with a situation where the vector is only partially moved to its new location. Moving the data back might also throw, and we end up with an inconsistent InlinedVector.
InlinedVector should either use copy constructors in that case, or insist that the move operator is declared nothrow.
The text was updated successfully, but these errors were encountered: