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
// 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
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());
+ }
}