[cfe-commits] [libcxx] r159918 - in /libcxx/trunk/include: deque vector

Howard Hinnant hhinnant at apple.com
Sun Jul 8 19:48:11 PDT 2012


You are right of course.  Test committed r159921.

Thanks,
Howard

On Jul 8, 2012, at 9:29 PM, Richard Smith wrote:

> Perhaps this would benefit from a test case? It seems subtle enough that I could imagine it breaking in the future.
> 
> On Sun, Jul 8, 2012 at 4:23 PM, Howard Hinnant <hhinnant at apple.com> wrote:
> Author: hhinnant
> Date: Sun Jul  8 18:23:04 2012
> New Revision: 159918
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=159918&view=rev
> Log:
> 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.
> 
> Modified:
>     libcxx/trunk/include/deque
>     libcxx/trunk/include/vector
> 
> Modified: libcxx/trunk/include/deque
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=159918&r1=159917&r2=159918&view=diff
> ==============================================================================
> --- libcxx/trunk/include/deque (original)
> +++ libcxx/trunk/include/deque Sun Jul  8 18:23:04 2012
> @@ -1966,6 +1966,7 @@
>          }
>          else
>          {
> +            value_type __tmp(_VSTD::forward<_Args>(__args)...);
>              iterator __b = __base::begin();
>              iterator __bm1 = _VSTD::prev(__b);
>              __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
> @@ -1973,7 +1974,7 @@
>              ++__base::size();
>              if (__pos > 1)
>                  __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
> -            *__b = value_type(_VSTD::forward<_Args>(__args)...);
> +            *__b = _VSTD::move(__tmp);
>          }
>      }
>      else
> @@ -1989,13 +1990,14 @@
>          }
>          else
>          {
> +            value_type __tmp(_VSTD::forward<_Args>(__args)...);
>              iterator __e = __base::end();
>              iterator __em1 = _VSTD::prev(__e);
>              __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
>              ++__base::size();
>              if (__de > 1)
>                  __e = _VSTD::move_backward(__e - __de, __em1, __e);
> -            *--__e = value_type(_VSTD::forward<_Args>(__args)...);
> +            *--__e = _VSTD::move(__tmp);
>          }
>      }
>      return __base::begin() + __pos;
> 
> Modified: libcxx/trunk/include/vector
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=159918&r1=159917&r2=159918&view=diff
> ==============================================================================
> --- libcxx/trunk/include/vector (original)
> +++ libcxx/trunk/include/vector Sun Jul  8 18:23:04 2012
> @@ -1681,8 +1681,9 @@
>          }
>          else
>          {
> +            value_type __tmp(_VSTD::forward<_Args>(__args)...);
>              __move_range(__p, this->__end_, __p + 1);
> -            *__p = value_type(_VSTD::forward<_Args>(__args)...);
> +            *__p = _VSTD::move(__tmp);
>          }
>      }
>      else
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 




More information about the cfe-commits mailing list