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.
How can std::shared_ptr offer a noexcept operator= ? Surely, if this shared_ptr is the
Share
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 toshared_ptr(r).swap(*this);But per
[C++11: 20.7.2.2.2],~shared_ptritself is notnoexcept.Unless I’ve misunderstood the way in which
noexceptworks, 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.