[libcxx] r213546 - In response to bug #20362, change the order of operations in vector move assignment so that if the allocator move assignment throws, we aren't left with two objects pointing at the same memory. This is not a complete fix; I am unconvinced that a complete fix is possible. With this change in place, we will leak the old contents of the vector. LWG issue #2106, when adopted, will make this problem illegal. Thanks to Thomas Koeppe for the report and analysis.

Marshall Clow mclow.lists at gmail.com
Mon Jul 21 08:11:13 PDT 2014


Author: marshall
Date: Mon Jul 21 10:11:13 2014
New Revision: 213546

URL: http://llvm.org/viewvc/llvm-project?rev=213546&view=rev
Log:
In response to bug #20362, change the order of operations in vector move assignment so that if the allocator move assignment throws, we aren't left with two objects pointing at the same memory. This is not a complete fix; I am unconvinced that a complete fix is possible. With this change in place, we will leak the old contents of the vector. LWG issue #2106, when adopted, will make this problem illegal. Thanks to Thomas Koeppe for the report and analysis.

Modified:
    libcxx/trunk/include/vector

Modified: libcxx/trunk/include/vector
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=213546&r1=213545&r2=213546&view=diff
==============================================================================
--- libcxx/trunk/include/vector (original)
+++ libcxx/trunk/include/vector Mon Jul 21 10:11:13 2014
@@ -1331,10 +1331,10 @@ vector<_Tp, _Allocator>::__move_assign(v
     _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
 {
     deallocate();
+    __base::__move_assign_alloc(__c); // this can throw
     this->__begin_ = __c.__begin_;
     this->__end_ = __c.__end_;
     this->__end_cap() = __c.__end_cap();
-    __base::__move_assign_alloc(__c);
     __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
 #if _LIBCPP_DEBUG_LEVEL >= 2
     __get_db()->swap(this, &__c);





More information about the cfe-commits mailing list