1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

SmallVector: Don't rely on having an assignment operator around in push_back for POD-like types.

llvm-svn: 155791
This commit is contained in:
Benjamin Kramer 2012-04-29 10:53:29 +00:00
parent 9769cec353
commit 74da5acd41
2 changed files with 14 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);
}
}