Commit ce4d7e9d authored by Marco Bubke's avatar Marco Bubke

Utils: Fix smallstring move assignment

Before the string was simply swapped with the other string which can lead
to an unexpected behavior for xvalues. Now the destructor of the source is
called and it is default initialized.

foo = std::move(bar);

bar would now hold the value of foo.

Change-Id: Ibea3f18333a168634b7faf2fdaf9b5b52c82d5cc
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 1d531104
......@@ -172,14 +172,17 @@ public:
}
BasicSmallString(BasicSmallString &&other) noexcept
: m_data(other.m_data)
{
m_data = other.m_data;
other.m_data = Internal::StringDataLayout<Size>();
}
BasicSmallString &operator=(BasicSmallString &&other) noexcept
{
swap(*this, other);
this->~BasicSmallString();
m_data = other.m_data;
other.m_data = Internal::StringDataLayout<Size>();
return *this;
}
......
......@@ -1495,7 +1495,7 @@ TEST(SmallString, ShortSmallStringMoveAssignment)
copy = std::move(text);
ASSERT_THAT(text, SmallString("more text"));
ASSERT_THAT(text, IsEmpty());
ASSERT_THAT(copy, SmallString("text"));
}
......@@ -1506,7 +1506,7 @@ TEST(SmallString, LongSmallStringMoveAssignment)
copy = std::move(text);
ASSERT_THAT(text, SmallString("more text"));
ASSERT_THAT(text, IsEmpty());
ASSERT_THAT(copy, SmallString("this is a very very very very long text"));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment