From 1559083a44c32e2d1a70ef9bc5a4942414b4469a Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Mon, 11 Dec 2017 19:22:59 +0000 Subject: [PATCH] Ensure moved-from container is cleared on move In all cases except for this optimistic attempt to reuse memory, the moved-from TinyPtrVector was left `empty()` at the end of this assignment. Though using a container after it's been moved from can be a bit sketchy, it's probably best to just be consistent here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320408 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/TinyPtrVector.h | 1 + unittests/ADT/TinyPtrVectorTest.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/llvm/ADT/TinyPtrVector.h b/include/llvm/ADT/TinyPtrVector.h index 79740713f75..73573d65e2b 100644 --- a/include/llvm/ADT/TinyPtrVector.h +++ b/include/llvm/ADT/TinyPtrVector.h @@ -97,6 +97,7 @@ public: if (RHS.Val.template is()) { V->clear(); V->push_back(RHS.front()); + RHS.Val = (EltTy)nullptr; return *this; } delete V; diff --git a/unittests/ADT/TinyPtrVectorTest.cpp b/unittests/ADT/TinyPtrVectorTest.cpp index 8d5fa406091..cc14ccc1e54 100644 --- a/unittests/ADT/TinyPtrVectorTest.cpp +++ b/unittests/ADT/TinyPtrVectorTest.cpp @@ -152,6 +152,12 @@ TYPED_TEST(TinyPtrVectorTest, CopyAndMoveCtorTest) { TypeParam Move(std::move(Copy2)); this->expectValues(Move, this->testArray(42)); this->expectValues(Copy2, this->testArray(0)); + + TypeParam MultipleElements(this->testArray(2)); + TypeParam SingleElement(this->testArray(1)); + MultipleElements = std::move(SingleElement); + this->expectValues(MultipleElements, this->testArray(1)); + this->expectValues(SingleElement, this->testArray(0)); } TYPED_TEST(TinyPtrVectorTest, CopyAndMoveTest) { -- 2.11.0