[PATCH] D47802: Allow std::vector to move construct its allocator

Scott Constable via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 5 15:32:47 PDT 2018


fidget324 created this revision.
fidget324 added reviewers: hiraditya, EricWF.
Herald added a subscriber: cfe-commits.

Fix an issue that was preventing std::vector from invoking the move
constructor on its allocator when appropriate.

Added a constructor to __vector_base which accepts an rvalue reference
 to the allocator, thus allowing the move constructor to be invoked.
 Previously, only a const lvalue reference was being accepted.

This fixes bug 37694: https://bugs.llvm.org/show_bug.cgi?id=37694.


Repository:
  rCXX libc++

https://reviews.llvm.org/D47802

Files:
  include/vector


Index: include/vector
===================================================================
--- include/vector
+++ include/vector
@@ -355,6 +355,7 @@
     __vector_base()
         _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
     _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
+    _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a);
     ~__vector_base();
 
     _LIBCPP_INLINE_VISIBILITY
@@ -438,6 +439,15 @@
 {
 }
 
+template <class _Tp, class _Allocator>
+inline _LIBCPP_INLINE_VISIBILITY
+__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a)
+    : __begin_(nullptr),
+      __end_(nullptr),
+      __end_cap_(nullptr, std::move(__a))
+{
+}
+
 template <class _Tp, class _Allocator>
 __vector_base<_Tp, _Allocator>::~__vector_base()
 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47802.150052.patch
Type: text/x-patch
Size: 810 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180605/46bbc285/attachment.bin>


More information about the cfe-commits mailing list