Merge pull request #40129 from kitaisreal/pod-array-assign-empty-array-fix

PODArray assign empty array fix
This commit is contained in:
Maksim Kita 2022-08-12 18:34:19 +02:00 committed by GitHub
commit 098436f012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -703,10 +703,9 @@ public:
size_t bytes_to_copy = this->byte_size(required_capacity);
if (bytes_to_copy)
{
memcpy(this->c_start, reinterpret_cast<const void *>(&*from_begin), bytes_to_copy);
this->c_end = this->c_start + bytes_to_copy;
}
this->c_end = this->c_start + bytes_to_copy;
}
// ISO C++ has strict ambiguity rules, thus we cannot apply TAllocatorParams here.

View File

@ -484,6 +484,35 @@ TEST(Common, PODArrayInsertFromItself)
}
}
TEST(Common, PODArrayAssign)
{
{
PaddedPODArray<UInt64> array;
array.push_back(1);
array.push_back(2);
array.assign({1, 2, 3});
ASSERT_EQ(array.size(), 3);
ASSERT_EQ(array, PaddedPODArray<UInt64>({1, 2, 3}));
}
{
PaddedPODArray<UInt64> array;
array.push_back(1);
array.push_back(2);
array.assign({});
ASSERT_TRUE(array.empty());
}
{
PaddedPODArray<UInt64> array;
array.assign({});
ASSERT_TRUE(array.empty());
}
}
TEST(Common, PODNoOverallocation)
{
/// Check that PaddedPODArray allocates for smaller number of elements than the power of two due to padding.