diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-06-08 16:00:02 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-06-08 16:00:02 +0000 |
commit | 789df06f876b5cc5ccd940ed76cb0b25f2fdb585 (patch) | |
tree | 81639a40807c8f2a134d6243b573257de6612818 /llvm/unittests/ADT/SmallVectorTest.cpp | |
parent | 8804e5cb499ab48ede014515f59cb557810ec29a (diff) | |
download | llvm-789df06f876b5cc5ccd940ed76cb0b25f2fdb585.zip llvm-789df06f876b5cc5ccd940ed76cb0b25f2fdb585.tar.gz llvm-789df06f876b5cc5ccd940ed76cb0b25f2fdb585.tar.bz2 |
Ensure SmallVector::insert doesn't overwrite the last element in the range with the already-moved-from value
This would cause the last element in a range to be in a moved-from state
after an insert at a non-end position, losing that value entirely in the
process.
Side note: move_backward is subtle. It copies [A, B) to C-1 and down.
(the fact that it decrements both the second and third iterators before
the first movement is the subtle part... kind of surprising, anyway)
llvm-svn: 210426
Diffstat (limited to 'llvm/unittests/ADT/SmallVectorTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/SmallVectorTest.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp index 58f5591..cccf93b 100644 --- a/llvm/unittests/ADT/SmallVectorTest.cpp +++ b/llvm/unittests/ADT/SmallVectorTest.cpp @@ -531,4 +531,26 @@ TEST(SmallVectorCustomTest, NoAssignTest) { EXPECT_EQ(42, vec.pop_back_val().x); } +struct MovedFrom { + bool hasValue; + MovedFrom() : hasValue(true) { + } + MovedFrom(MovedFrom&& m) : hasValue(m.hasValue) { + m.hasValue = false; + } + MovedFrom &operator=(MovedFrom&& m) { + hasValue = m.hasValue; + m.hasValue = false; + return *this; + } +}; + +TEST(SmallVectorTest, MidInsert) { + SmallVector<MovedFrom, 3> v; + v.push_back(MovedFrom()); + v.insert(v.begin(), MovedFrom()); + for (MovedFrom &m : v) + EXPECT_TRUE(m.hasValue); +} + } |