[PATCH] D62688: [Analyzer] Iterator Checkers - Model `empty()` method of containers
Kristóf Umann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 18 19:40:02 PDT 2019
Szelethus added inline comments.
================
Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:1741-1763
+bool isContainer(const CXXRecordDecl *CRD) {
+ if (!CRD)
+ return false;
+
+ for (const auto *Decl : CRD->decls()) {
+ const auto *TD = dyn_cast<TypeDecl>(Decl);
+ if (!TD)
----------------
But what if we have a container for which the iterator isn't an inline class, or we don't even have an in-class alias for it? I think whether the record has a `begin`/`end` method would be a better heuristic.
================
Comment at: test/Analysis/iterator-range.cpp:247
+void empty(const std::vector<int> &V) {
+ for (auto n: V) {}
+ *V.begin(); // expected-warning{{Past-the-end iterator dereferenced}}
----------------
Aha, the for loop is here to force a state split on whether `V` is empty or not, correct?
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62688/new/
https://reviews.llvm.org/D62688
More information about the cfe-commits
mailing list