[PATCH] D70368: [clang-tidy] Rewrite modernize-avoid-bind check
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 20 07:28:19 PST 2019
aaron.ballman added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp:153
+
+ return HNM.matchesNode(*dyn_cast<NamedDecl>(D));
+}
----------------
zturner wrote:
> aaron.ballman wrote:
> > This should probably use `cast<>` if it's going to assume the returned value is never null.
> Good point. Since we're talking about this code anyway, it felt super hacky to instantiate an AST matcher just to check for the qualified name of a Decl. Is there a better way to do this?
Since you only care about named call declarations, I think you could probably get away with:
```
if (const auto *ND = dyn_cast<NamedDecl>(CE->getCalleeDecl())) {
const std::string &Str = ND->getQualifiedNameAsString();
if (Str == "::boost::ref" || Str == "::std::ref") {
...
}
}
```
================
Comment at: clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp:167
+ }
+ } else if (const auto *ThisExpr = dyn_cast<CXXThisExpr>(Statement))
+ return true;
----------------
`isa<CXXThisExpr>(Statement)`
================
Comment at: clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp:428-429
+ if (const auto *DRE = dyn_cast<DeclRefExpr>(CallExpression)) {
+ if (const auto *FD = dyn_cast<FunctionDecl>(DRE->getDecl()))
+ return FD;
+ }
----------------
I think this can be replaced with: `return dyn_cast<FunctionDecl>(DRE->getDecl());`
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70368/new/
https://reviews.llvm.org/D70368
More information about the cfe-commits
mailing list