mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 11:07:45 +00:00
AK: Destroy original value when assigning to Variant
This commit is contained in:
parent
515e2d9734
commit
39dd13fd17
2 changed files with 12 additions and 0 deletions
|
@ -266,6 +266,9 @@ public:
|
||||||
requires(!(IsTriviallyCopyConstructible<Ts> && ...) || !(IsTriviallyDestructible<Ts> && ...))
|
requires(!(IsTriviallyCopyConstructible<Ts> && ...) || !(IsTriviallyDestructible<Ts> && ...))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
if constexpr (!(IsTriviallyDestructible<Ts> && ...)) {
|
||||||
|
Helper::delete_(m_index, m_data);
|
||||||
|
}
|
||||||
m_index = other.m_index;
|
m_index = other.m_index;
|
||||||
Helper::copy_(other.m_index, other.m_data, m_data);
|
Helper::copy_(other.m_index, other.m_data, m_data);
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -276,6 +279,9 @@ public:
|
||||||
requires(!(IsTriviallyMoveConstructible<Ts> && ...) || !(IsTriviallyDestructible<Ts> && ...))
|
requires(!(IsTriviallyMoveConstructible<Ts> && ...) || !(IsTriviallyDestructible<Ts> && ...))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
if constexpr (!(IsTriviallyDestructible<Ts> && ...)) {
|
||||||
|
Helper::delete_(m_index, m_data);
|
||||||
|
}
|
||||||
m_index = other.m_index;
|
m_index = other.m_index;
|
||||||
Helper::move_(other.m_index, other.m_data, m_data);
|
Helper::move_(other.m_index, other.m_data, m_data);
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -57,6 +57,12 @@ TEST_CASE(destructor)
|
||||||
Variant<DestructionChecker> test_variant { DestructionChecker { was_destroyed } };
|
Variant<DestructionChecker> test_variant { DestructionChecker { was_destroyed } };
|
||||||
}
|
}
|
||||||
EXPECT(was_destroyed);
|
EXPECT(was_destroyed);
|
||||||
|
|
||||||
|
bool was_destroyed_when_assigned_to = false;
|
||||||
|
Variant<DestructionChecker, int> original { DestructionChecker { was_destroyed_when_assigned_to } };
|
||||||
|
Variant<DestructionChecker, int> other { 42 };
|
||||||
|
original = other;
|
||||||
|
EXPECT(was_destroyed_when_assigned_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(move_moves)
|
TEST_CASE(move_moves)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue