NoQ created this revision. NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, rnkovacs, Szelethus. Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, baloghadamsoftware.
This covers methods that //may// reset the state depending on the value of the argument: `resize()`, `shrink_to_fit()`, and `shrink()`. The latter is something i've seen on a custom collection; we don't have to hardcode those, but i guess it's a good safe way to be a bit better out of the box. As a TODO, we might want to warn anyway when the value of the argument is not `0`. Repository: rC Clang https://reviews.llvm.org/D54563 Files: lib/StaticAnalyzer/Checkers/MoveChecker.cpp test/Analysis/use-after-move.cpp Index: test/Analysis/use-after-move.cpp =================================================================== --- test/Analysis/use-after-move.cpp +++ test/Analysis/use-after-move.cpp @@ -15,6 +15,8 @@ namespace std { +typedef __typeof(sizeof(int)) size_t; + template <typename> struct remove_reference; @@ -110,6 +112,7 @@ void reset(); void destroy(); void clear(); + void resize(std::size_t); bool empty() const; bool isEmpty() const; operator bool() const; @@ -403,6 +406,13 @@ 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. Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/MoveChecker.cpp +++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp @@ -334,7 +334,8 @@ if (MethodDec->getDeclName().isIdentifier()) { std::string MethodName = MethodDec->getName().lower(); if (MethodName == "reset" || MethodName == "clear" || - MethodName == "destroy") + MethodName == "destroy" || MethodName == "resize" || + MethodName == "shrink" || MethodName == "shrink_to_fit") return true; } return false;
Index: test/Analysis/use-after-move.cpp =================================================================== --- test/Analysis/use-after-move.cpp +++ test/Analysis/use-after-move.cpp @@ -15,6 +15,8 @@ namespace std { +typedef __typeof(sizeof(int)) size_t; + template <typename> struct remove_reference; @@ -110,6 +112,7 @@ void reset(); void destroy(); void clear(); + void resize(std::size_t); bool empty() const; bool isEmpty() const; operator bool() const; @@ -403,6 +406,13 @@ 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. Index: lib/StaticAnalyzer/Checkers/MoveChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/MoveChecker.cpp +++ lib/StaticAnalyzer/Checkers/MoveChecker.cpp @@ -334,7 +334,8 @@ if (MethodDec->getDeclName().isIdentifier()) { std::string MethodName = MethodDec->getName().lower(); if (MethodName == "reset" || MethodName == "clear" || - MethodName == "destroy") + MethodName == "destroy" || MethodName == "resize" || + MethodName == "shrink" || MethodName == "shrink_to_fit") return true; } return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits