]> granicus.if.org Git - clang/commitdiff
[analyzer] MoveChecker: Add one more common resetting method, "append".
authorArtem Dergachev <artem.dergachev@gmail.com>
Fri, 18 Jan 2019 00:16:25 +0000 (00:16 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Fri, 18 Jan 2019 00:16:25 +0000 (00:16 +0000)
This is especially crucial for reports related to use-after-move of
standard library objects.

rdar://problem/47338505

Differential Revision: https://reviews.llvm.org/D56824

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351500 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/MoveChecker.cpp
test/Analysis/use-after-move.cpp

index 6efa2dfbe5b476c9c6963259dc3d22e0e2ec5699..95b5ac6d1dd29714d23d5f3306cdaf497ac69637 100644 (file)
@@ -502,9 +502,9 @@ bool MoveChecker::isStateResetMethod(const CXXMethodDecl *MethodDec) const {
     std::string MethodName = MethodDec->getName().lower();
     // TODO: Some of these methods (eg., resize) are not always resetting
     // the state, so we should consider looking at the arguments.
-    if (MethodName == "reset" || MethodName == "clear" ||
-        MethodName == "destroy" || MethodName == "resize" ||
-        MethodName == "shrink")
+    if (MethodName == "assign" || MethodName == "clear" ||
+        MethodName == "destroy" || MethodName == "reset" ||
+        MethodName == "resize" || MethodName == "shrink")
       return true;
   }
   return false;
index 280724512f8aa6b824afefdcfd914db11983801d..435976c5a7c2962cb600a73c5da2ab4a050180d4 100644 (file)
@@ -89,6 +89,7 @@ public:
   void destroy();
   void clear();
   void resize(std::size_t);
+  void assign(const A &);
   bool empty() const;
   bool isEmpty() const;
   operator bool() const;
@@ -531,6 +532,13 @@ void moveStateResetFunctionsTest() {
     a.foo();   // no-warning
     a.b.foo(); // no-warning
   }
+  {
+    A a;
+    A b = std::move(a);
+    a.assign(A()); // no-warning
+    a.foo();   // no-warning
+    a.b.foo(); // no-warning
+  }
 }
 
 // Moves or uses that occur as part of template arguments.