[PATCH] D45444: [clang-tidy] WIP: implement new check for const-correctness
Shuai Wang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 29 11:19:09 PDT 2018
shuaiwang added inline comments.
================
Comment at: clang-tidy/cppcoreguidelines/ConstCheck.cpp:229-237
+ const auto *UseExpr = selectFirst<Expr>("use", Usage);
+
+ // The declared variables was used in non-const conserving way and can not
+ // be declared as const.
+ if (UseExpr && Scopes[Scope]->isMutated(UseExpr)) {
+ // diag(UseExpr->getLocStart(), "Investigating starting with this use",
+ // DiagnosticIDs::Note);
----------------
I think we need to loop over usages instead of just checking the first, i.e.:
```
for (const auto &Nodes : Usage) {
const auto* UseExpr = Nodes.getNodeAs<Expr>("use");
if (UseExpr && isMutated(UseExpr)) return true;
}
```
I'll add a helper function in the MutationAnalyzer for checking varDecl directly as well per your comment there, which you'll be able to use directly in this check. Before that's ready (and if you have time of course) could you help check how many false positives are left with this change?
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D45444
More information about the cfe-commits
mailing list