Index: test/containers/Copyable.h =================================================================== --- test/containers/Copyable.h +++ test/containers/Copyable.h @@ -12,7 +12,32 @@ class Copyable { + int data_; public: + Copyable(int data = 0) : data_(data) { assert(data != -1); } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + Copyable(Copyable &&x) : data_(x.data_) { + assert(x.data_ != -1); + x.data_ = -1; + } + Copyable &operator=(Copyable &&x) { + assert(x.data_ != -1); + data_ = x.data_; + x.data_ = -1; + return *this; + } +#endif + Copyable(const Copyable &x) : data_(x.data_) { + assert(x.data_ != -1); + } + Copyable &operator=(const Copyable &x) { + assert(x.data_ != -1); + data_ = x.data_; + return *this; + } + + int get() const {return data_;} + bool operator==(const Copyable& x) const { return data_ == x.data_; } }; #endif // COPYABLE_H Index: test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp =================================================================== --- test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp +++ test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp @@ -19,6 +19,7 @@ #include #include #include "../../../stack_allocator.h" +#include "../../../Copyable.h" #include "test_iterators.h" #include "min_allocator.h" #include "asan_testing.h" @@ -151,4 +152,27 @@ } #endif #endif + { + // FIXME: Test this in cases that will guarantee reallocation is + // performed or avoided. + std::vector v; + for (unsigned i = 1; i != 5; ++i) + v.push_back(Copyable(i)); + // some elements before the range, some elements in the range but before + // the insertion point, elements in the range after the insertion, and + // after the range entirely. + std::vector::iterator i = v.insert(v.begin() + 2, v.begin() + 1, v.begin() + 3); + assert(v.size() == 6); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 2); + // Original prefix + assert(v[0] == Copyable(1)); + assert(v[1] == Copyable(2)); + // Inserted elements + assert(v[2] == Copyable(2)); + assert(v[3] == Copyable(3)); + // Original suffix + assert(v[4] == Copyable(3)); + assert(v[5] == Copyable(4)); + } }