Protect against self-move-assignment to fix stable_sort in MSVC

This commit is contained in:
rdb 2015-07-17 15:55:24 +02:00
parent 828e52578d
commit dafae50ce2
2 changed files with 17 additions and 11 deletions

View File

@ -71,14 +71,17 @@ PointerToBase(PointerToBase<T> &&from) NOEXCEPT {
template<class T>
INLINE void PointerToBase<T>::
reassign(PointerToBase<T> &&from) NOEXCEPT {
To *old_ptr = (To *)this->_void_ptr;
// Protect against self-move-assignment.
if (from._void_ptr != this->_void_ptr) {
To *old_ptr = (To *)this->_void_ptr;
this->_void_ptr = from._void_ptr;
from._void_ptr = NULL;
this->_void_ptr = from._void_ptr;
from._void_ptr = NULL;
// Now delete the old pointer.
if (old_ptr != (To *)NULL) {
unref_delete(old_ptr);
// Now delete the old pointer.
if (old_ptr != (To *)NULL) {
unref_delete(old_ptr);
}
}
}
#endif // USE_MOVE_SEMANTICS

View File

@ -102,12 +102,15 @@ CopyOnWritePointer(CopyOnWritePointer &&move) NOEXCEPT :
////////////////////////////////////////////////////////////////////
INLINE void CopyOnWritePointer::
operator = (CopyOnWritePointer &&move) NOEXCEPT {
CopyOnWriteObject *old_object = _cow_object;
_cow_object = move._cow_object;
move._cow_object = NULL;
// Protect against self-move-assignment.
if (move._cow_object != _cow_object) {
CopyOnWriteObject *old_object = _cow_object;
_cow_object = move._cow_object;
move._cow_object = NULL;
if (old_object != (CopyOnWriteObject *)NULL) {
cache_unref_delete(old_object);
if (old_object != (CopyOnWriteObject *)NULL) {
cache_unref_delete(old_object);
}
}
}
#endif // USE_MOVE_SEMANTICS