How can std::shared_ptr
offer a noexcept
operator=
? Surely, if this shared_ptr
is the last one, then it will have to destroy its contents, and it can't guarantee that the destructor of that object does not throw, or the custom deleter used originally does not throw.
Looks like a defect to me, though not one I can find in the active issues list (though #2104 is similar).
Per [C++11: 20.7.2.2.3/1]
, the assignment is defined to be equivalent to shared_ptr(r).swap(*this)
;
But per [C++11: 20.7.2.2.2]
, ~shared_ptr
itself is not noexcept
.
Unless I've misunderstood the way in which noexcept
works, this must be an error.
Alternatively it could simply mean that the assignment operator is only usable when neither the underlying object type nor the deleter type throw on destruction, though even in such a scenario, the lack of any informative note in the standard wording makes me think that this is unlikely.
According to the isocpp forums, shared_ptr
simply assumes that the deleter will not throw, and otherwise is UB. This would mean that the real defect is that shared_ptr
's destructor is not marked as nothrow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With