From: Philip Pronin Date: Sat, 2 Feb 2013 06:41:53 +0000 (-0800) Subject: assert on self move assignment X-Git-Tag: v0.22.0~1069 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=2a80dba785170e73c1630998bc8054c8f7b0eb39;p=folly.git assert on self move assignment Test Plan: ran tests in dbg Reviewed By: tudorb@fb.com FB internal diff: D696964 --- diff --git a/folly/FBString.h b/folly/FBString.h index a0a86f46..5f76d2a6 100644 --- a/folly/FBString.h +++ b/folly/FBString.h @@ -1042,8 +1042,8 @@ public: ~basic_fbstring() { } - basic_fbstring& operator=(const basic_fbstring & lhs) { - if (&lhs == this) { + basic_fbstring& operator=(const basic_fbstring& lhs) { + if (FBSTRING_UNLIKELY(&lhs == this)) { return *this; } auto const oldSize = size(); @@ -1066,6 +1066,8 @@ 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); // No need of this anymore this->~basic_fbstring(); // Move the goner into this