[analyzer] MoveChecker: Add more common state resetting methods.

Includes "resize" and "shrink" because they can reset the object to a known
state in certain circumstances.

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

llvm-svn: 348235
This commit is contained in:
Artem Dergachev 2018-12-04 03:38:08 +00:00
parent 821b38f526
commit f3f0366296
2 changed files with 14 additions and 1 deletions

View File

@ -343,8 +343,11 @@ bool MoveChecker::isStateResetMethod(const CXXMethodDecl *MethodDec) const {
return true;
if (MethodDec->getDeclName().isIdentifier()) {
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 == "destroy" || MethodName == "resize" ||
MethodName == "shrink")
return true;
}
return false;

View File

@ -15,6 +15,8 @@
namespace std {
typedef __typeof(sizeof(int)) size_t;
template <typename>
struct remove_reference;
@ -110,6 +112,7 @@ public:
void reset();
void destroy();
void clear();
void resize(std::size_t);
bool empty() const;
bool isEmpty() const;
operator bool() const;
@ -403,6 +406,13 @@ void moveStateResetFunctionsTest() {
a.foo(); // no-warning
a.b.foo(); // no-warning
}
{
A a;
A b = std::move(a);
a.resize(0); // no-warning
a.foo(); // no-warning
a.b.foo(); // no-warning
}
}
// Moves or uses that occur as part of template arguments.