aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2012-04-29 10:53:29 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2012-04-29 10:53:29 +0000
commit74a12a46a04b9d2bcd1251a641b7cb64dfc0c5f8 (patch)
tree47ef66ca8d5c9aa16a659f826b44d0f96df3c65d
parent3b6e07cd1a71df7b8a367adbc5635089a76ce942 (diff)
downloadllvm-74a12a46a04b9d2bcd1251a641b7cb64dfc0c5f8.zip
llvm-74a12a46a04b9d2bcd1251a641b7cb64dfc0c5f8.tar.gz
llvm-74a12a46a04b9d2bcd1251a641b7cb64dfc0c5f8.tar.bz2
SmallVector: Don't rely on having an assignment operator around in push_back for POD-like types.
llvm-svn: 155791
-rw-r--r--llvm/include/llvm/ADT/SmallVector.h2
-rw-r--r--llvm/unittests/ADT/SmallVectorTest.cpp13
2 files changed, 14 insertions, 1 deletions
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index 0d9d0d1..8b75ff5 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/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/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp
index d5bfe76..c2542d6 100644
--- a/llvm/unittests/ADT/SmallVectorTest.cpp
+++ b/llvm/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<notassignable, 2> vec;
+ vec.push_back(notassignable(x));
+ x = 42;
+ EXPECT_EQ(42, vec.pop_back_val().x);
+}
+
}