diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-06-08 16:55:13 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-06-08 16:55:13 +0000 |
commit | 40d4e34a1fa3efce647338c3929c2ad3244177f0 (patch) | |
tree | 1602c443ff7421d81f0485770b2ebbac1e365ce7 /llvm/unittests/ADT/SmallVectorTest.cpp | |
parent | d327828141855d7317116e9ef0bc74924b8527d9 (diff) | |
download | llvm-40d4e34a1fa3efce647338c3929c2ad3244177f0.zip llvm-40d4e34a1fa3efce647338c3929c2ad3244177f0.tar.gz llvm-40d4e34a1fa3efce647338c3929c2ad3244177f0.tar.bz2 |
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)
llvm-svn: 210429
Diffstat (limited to 'llvm/unittests/ADT/SmallVectorTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/SmallVectorTest.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp index cccf93b..935c761 100644 --- a/llvm/unittests/ADT/SmallVectorTest.cpp +++ b/llvm/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"); |