From: Artem Dergachev Date: Fri, 18 Jan 2019 00:16:25 +0000 (+0000) Subject: [analyzer] MoveChecker: Add one more common resetting method, "append". X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3dd4ecf43e5928912b6470a76e8a496735ec064a;p=clang [analyzer] MoveChecker: Add one more common resetting method, "append". 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 --- diff --git a/lib/StaticAnalyzer/Checkers/MoveChecker.cpp b/lib/StaticAnalyzer/Checkers/MoveChecker.cpp index 6efa2dfbe5..95b5ac6d1d 100644 --- a/lib/StaticAnalyzer/Checkers/MoveChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MoveChecker.cpp @@ -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; diff --git a/test/Analysis/use-after-move.cpp b/test/Analysis/use-after-move.cpp index 280724512f..435976c5a7 100644 --- a/test/Analysis/use-after-move.cpp +++ b/test/Analysis/use-after-move.cpp @@ -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.