[libc++] Fix PR34898 - vector iterator constructors and assign method perform push_ba...
authorEric Fiselier <eric@efcs.ca>
Tue, 17 Oct 2017 13:03:17 +0000 (13:03 +0000)
committerEric Fiselier <eric@efcs.ca>
Tue, 17 Oct 2017 13:03:17 +0000 (13:03 +0000)
commit1c0cedccb62480d61bc4c0c31c871f9096b4873a
tree7f0273afe6543f92aa56aa048e3c9ed812386c9b
parent228340315d655373219db0d61bd48e390b9f5735
[libc++] Fix PR34898 - vector iterator constructors and assign method perform push_back instead of emplace_back.

Summary:
The constructors `vector(Iter, Iter, Alloc = Alloc{})` and `assign(Iter, Iter)` don't correctly perform EmplaceConstruction from the result of dereferencing the iterator. This results in them performing an additional and unneeded copy.

This patch addresses the issue by correctly using `emplace_back` in C++11 and newer.

There are also some bugs in our `insert` implementation, but those will be handled separately.

@mclow.lists We should probably merge this into 5.1, agreed?

Reviewers: mclow.lists, dlj, EricWF

Reviewed By: mclow.lists, EricWF

Subscribers: cfe-commits, mclow.lists

Differential Revision: https://reviews.llvm.org/D38757

llvm-svn: 315994
12 files changed:
libcxx/include/deque
libcxx/include/list
libcxx/include/vector
libcxx/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp
libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp
libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp
libcxx/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp [new file with mode: 0644]
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
libcxx/test/support/container_test_types.h
libcxx/test/support/emplace_constructible.h [new file with mode: 0644]