summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-06-08 16:55:13 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-06-08 16:55:13 +0000
commit9262e52075b293289f91ccab06d04536d3d53a46 (patch)
tree70ab7fb853e5b5effe05d4644ba5dd493f0fd2e3 /unittests
parentbef256f49b77b17503b23699466d9bfc2f02d65f (diff)
downloadllvm-9262e52075b293289f91ccab06d04536d3d53a46.tar.gz
llvm-9262e52075b293289f91ccab06d04536d3d53a46.tar.bz2
llvm-9262e52075b293289f91ccab06d04536d3d53a46.tar.xz
Fix some more moving-from-moved-from objects issues in SmallVector
(& because it makes it easier to test, this also improves correctness/performance slightly by moving the last element in an insert operation, rather than copying it) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210429 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/SmallVectorTest.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp
index cccf93b6bc..935c761ca7 100644
--- a/unittests/ADT/SmallVectorTest.cpp
+++ b/unittests/ADT/SmallVectorTest.cpp
@@ -42,12 +42,15 @@ public:
}
Constructable(const Constructable & src) : constructed(true) {
+ EXPECT_TRUE(src.constructed);
value = src.value;
++numConstructorCalls;
}
Constructable(Constructable && src) : constructed(true) {
+ EXPECT_TRUE(src.constructed);
value = src.value;
+ src.value = -1;
++numConstructorCalls;
}
@@ -59,6 +62,7 @@ public:
Constructable & operator=(const Constructable & src) {
EXPECT_TRUE(constructed);
+ EXPECT_TRUE(src.constructed);
value = src.value;
++numAssignmentCalls;
return *this;
@@ -66,7 +70,9 @@ public:
Constructable & operator=(Constructable && src) {
EXPECT_TRUE(constructed);
+ EXPECT_TRUE(src.constructed);
value = src.value;
+ src.value = -1;
++numAssignmentCalls;
return *this;
}
@@ -413,6 +419,18 @@ TYPED_TEST(SmallVectorTest, InsertTest) {
this->assertValuesInOrder(this->theVector, 4u, 1, 77, 2, 3);
}
+// Insert a copy of a single element.
+TYPED_TEST(SmallVectorTest, InsertCopy) {
+ SCOPED_TRACE("InsertTest");
+
+ this->makeSequence(this->theVector, 1, 3);
+ Constructable C(77);
+ typename TypeParam::iterator I =
+ this->theVector.insert(this->theVector.begin() + 1, C);
+ EXPECT_EQ(this->theVector.begin() + 1, I);
+ this->assertValuesInOrder(this->theVector, 4u, 1, 77, 2, 3);
+}
+
// Insert repeated elements.
TYPED_TEST(SmallVectorTest, InsertRepeatedTest) {
SCOPED_TRACE("InsertRepeatedTest");