assert on self move assignment
authorPhilip Pronin <philipp@fb.com>
Sat, 2 Feb 2013 06:41:53 +0000 (22:41 -0800)
committerJordan DeLong <jdelong@fb.com>
Tue, 19 Mar 2013 00:05:16 +0000 (17:05 -0700)
Test Plan: ran tests in dbg

Reviewed By: tudorb@fb.com

FB internal diff: D696964

folly/FBString.h

index a0a86f466e5bf1f31b6d16a79e23735895ae996f..5f76d2a68a9655e90c3aee35002b6344a2552ec5 100644 (file)
@@ -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