Commit 4b9cc255 authored by Philip Pronin's avatar Philip Pronin Committed by Sara Golemon

fix fbstring move assignment operator

Summary:
21.4.2 [string.cons] / 23 says

> If *this and str are the same object, the member has no effect.

That means we have to support self-move-assignment.

Test Plan: added test which triggered assertion, ran it

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D785057
parent 427f1e4c
......@@ -1070,8 +1070,11 @@ public:
// Move assignment
basic_fbstring& operator=(basic_fbstring&& goner) {
// Self move assignment is illegal, see 17.6.4.9 for the explanation
assert(&goner != this);
if (FBSTRING_UNLIKELY(&goner == this)) {
// Compatibility with std::basic_string<>,
// 21.4.2 [string.cons] / 23 requires self-move-assignment support.
return *this;
}
// No need of this anymore
this->~basic_fbstring();
// Move the goner into this
......
......@@ -1015,11 +1015,15 @@ TEST(FBString, testFixedBugs) {
cp += "bb";
}
}
{
// D661622
{ // D661622
folly::basic_fbstring<wchar_t> s;
EXPECT_EQ(0, s.size());
}
{ // D785057
fbstring str(1337, 'f');
std::swap(str, str);
EXPECT_EQ(1337, str.size());
}
}
......
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