From: Benjamin Kramer Date: Sun, 29 Apr 2012 10:53:29 +0000 (+0000) Subject: SmallVector: Don't rely on having an assignment operator around in push_back for... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3703baacf5c17425a07d57583148086a746c5f98;p=oota-llvm.git SmallVector: Don't rely on having an assignment operator around in push_back for POD-like types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155791 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index 0d9d0d12e86..8b75ff56a3c 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -252,7 +252,7 @@ public: void push_back(const T &Elt) { if (this->EndX < this->CapacityX) { Retry: - *this->end() = Elt; + memcpy(this->end(), &Elt, sizeof(T)); this->setEnd(this->end()+1); return; } diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp index d5bfe768003..c2542d614e2 100644 --- a/unittests/ADT/SmallVectorTest.cpp +++ b/unittests/ADT/SmallVectorTest.cpp @@ -413,4 +413,17 @@ TEST_F(SmallVectorTest, IteratorTest) { theVector.insert(theVector.end(), L.begin(), L.end()); } +struct notassignable { + int &x; + notassignable(int &x) : x(x) {} +}; + +TEST_F(SmallVectorTest, NoAssignTest) { + int x = 0; + SmallVector vec; + vec.push_back(notassignable(x)); + x = 42; + EXPECT_EQ(42, vec.pop_back_val().x); +} + }