[PATCH] Test std::vector<T>::insert(iter, iter, iter) when inserting a range into itself.
David Blaikie
dblaikie at gmail.com
Tue Jun 10 11:54:25 PDT 2014
Hi mclow.lists,
Also add move semantics to Copyable to ensure that attempts to copy or
move from an already moved-from object essert. This should help make
other existing test cases more robust as well.
http://reviews.llvm.org/D4088
Files:
test/containers/Copyable.h
test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp
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 <vector>
#include <cassert>
#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<Copyable> 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<Copyable>::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));
+ }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4088.10291.patch
Type: text/x-patch
Size: 2536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140610/fddfa74e/attachment.bin>
More information about the cfe-commits
mailing list