Erase the source SeArray immediately in move assignment operator.

This commit is contained in:
hashlag committed 2026-10-18 02:40:52 +03:00
1 parent fc67ba6b46
commit 0be43c9cf6
2 files changed
+23 -1

No files matched your search

+14 -1
View File
@@ -27,7 +27,20 @@ public:
}
SeArray & operator=(const SeArray & other) = default;
SeArray & operator=(SeArray && other) = default;
SeArray & operator=(SeArray && other)
{
if (this == &other)
{
return *this;
}
EraseImpl();
Storage_ = std::move(other.Storage_);
other.EraseImpl();
return *this;
}
~SeArray()
{
+9
View File
@@ -305,6 +305,9 @@ TEST(SeArrayTests, MoveAssignTest)
ASSERT_EQ(0xaa, arr1[0]);
ASSERT_EQ(0xbb, arr1[1]);
ASSERT_EQ(0, arr2[0]);
ASSERT_EQ(0, arr2[1]);
}
{
@@ -324,6 +327,12 @@ TEST(SeArrayTests, MoveAssignTest)
ASSERT_EQ(0, arr1[2]);
ASSERT_EQ(0, arr1[3]);
ASSERT_EQ(0, arr1[4]);
ASSERT_EQ(0, arr2[0]);
ASSERT_EQ(0, arr2[1]);
ASSERT_EQ(0, arr2[2]);
ASSERT_EQ(0, arr2[3]);
ASSERT_EQ(0, arr2[4]);
}
}