<div class="gmail_quote">Perhaps this would benefit from a test case? It seems subtle enough that I could imagine it breaking in the future.</div><div class="gmail_quote"><br></div><div class="gmail_quote">On Sun, Jul 8, 2012 at 4:23 PM, Howard Hinnant <span dir="ltr"><<a href="mailto:hhinnant@apple.com" target="_blank">hhinnant@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: hhinnant<br>
Date: Sun Jul  8 18:23:04 2012<br>
New Revision: 159918<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=159918&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=159918&view=rev</a><br>
Log:<br>
Change emplace for vector and deque to create the temporary (when necessary) before any changes to the container are made.  Nikolay Ivchenkov deserves the credit for pushing this problem and the solution for it.<br>
<br>
Modified:<br>
    libcxx/trunk/include/deque<br>
    libcxx/trunk/include/vector<br>
<br>
Modified: libcxx/trunk/include/deque<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=159918&r1=159917&r2=159918&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=159918&r1=159917&r2=159918&view=diff</a><br>

==============================================================================<br>
--- libcxx/trunk/include/deque (original)<br>
+++ libcxx/trunk/include/deque Sun Jul  8 18:23:04 2012<br>
@@ -1966,6 +1966,7 @@<br>
         }<br>
         else<br>
         {<br>
+            value_type __tmp(_VSTD::forward<_Args>(__args)...);<br>
             iterator __b = __base::begin();<br>
             iterator __bm1 = _VSTD::prev(__b);<br>
             __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));<br>
@@ -1973,7 +1974,7 @@<br>
             ++__base::size();<br>
             if (__pos > 1)<br>
                 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);<br>
-            *__b = value_type(_VSTD::forward<_Args>(__args)...);<br>
+            *__b = _VSTD::move(__tmp);<br>
         }<br>
     }<br>
     else<br>
@@ -1989,13 +1990,14 @@<br>
         }<br>
         else<br>
         {<br>
+            value_type __tmp(_VSTD::forward<_Args>(__args)...);<br>
             iterator __e = __base::end();<br>
             iterator __em1 = _VSTD::prev(__e);<br>
             __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));<br>
             ++__base::size();<br>
             if (__de > 1)<br>
                 __e = _VSTD::move_backward(__e - __de, __em1, __e);<br>
-            *--__e = value_type(_VSTD::forward<_Args>(__args)...);<br>
+            *--__e = _VSTD::move(__tmp);<br>
         }<br>
     }<br>
     return __base::begin() + __pos;<br>
<br>
Modified: libcxx/trunk/include/vector<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=159918&r1=159917&r2=159918&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=159918&r1=159917&r2=159918&view=diff</a><br>

==============================================================================<br>
--- libcxx/trunk/include/vector (original)<br>
+++ libcxx/trunk/include/vector Sun Jul  8 18:23:04 2012<br>
@@ -1681,8 +1681,9 @@<br>
         }<br>
         else<br>
         {<br>
+            value_type __tmp(_VSTD::forward<_Args>(__args)...);<br>
             __move_range(__p, this->__end_, __p + 1);<br>
-            *__p = value_type(_VSTD::forward<_Args>(__args)...);<br>
+            *__p = _VSTD::move(__tmp);<br>
         }<br>
     }<br>
     else<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br>