[PATCH] D45444: [clang-tidy] WIP: implement new check for const-correctness

Jonas Toth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 30 01:51:30 PDT 2018


JonasToth added a comment.

I will migrate to the new API today evening (european time).

Why do you think that looping is required? From my understanding, we
need the first usage (DeclRefExpr) to get the analysis started. The
analysis itself will check all remaining uses. Is this necessary,
because we analysis on a `Expr` basis?

Am 29.04.2018 um 20:19 schrieb Shuai Wang via Phabricator:

> 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


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45444





More information about the cfe-commits mailing list