[clang-tools-extra] [clang-tidy] Fix false positives with deducing this in `readability-convert-member-functions-to-static` check (PR #141391)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sat May 24 22:43:23 PDT 2025
================
@@ -62,6 +62,16 @@ AST_MATCHER(CXXMethodDecl, usesThis) {
return false; // Stop traversal.
}
+ bool VisitDeclRefExpr(const DeclRefExpr *E) {
+ if (const auto *PVD = dyn_cast_if_present<ParmVarDecl>(E->getDecl());
+ PVD && PVD->isExplicitObjectParameter()) {
+ Used = true;
+ return false; // Stop traversal.
+ }
+
+ return true;
+ }
----------------
vbvictor wrote:
I think we should not introduce a new method in `RecursiveASTVisitor`.
As for now, you would traverse every `DeclRefExpr` in function body trying to `dyn_cast` which is not efficient.
Instead, We should only check for `this` in methods parameters, so you can write
```cpp
Finder->addMatcher(
cxxMethodDecl(
isDefinition(), isUserProvided(),
unless(anyOf(
hasAnyParameter(isExplicitObjectParameter())
```
https://github.com/llvm/llvm-project/pull/141391
More information about the cfe-commits
mailing list