================
@@ -69,9 +73,13 @@ void 
LambdaFunctionNameCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 }
 
 void LambdaFunctionNameCheck::registerMatchers(MatchFinder *Finder) {
-  // Match on PredefinedExprs inside a lambda.
-  Finder->addMatcher(predefinedExpr(hasAncestor(lambdaExpr())).bind("E"),
-                     this);
+  Finder->addMatcher(
+      cxxMethodDecl(isInLambda(),
+                    hasBody(hasDescendant(expr(
----------------
PiotrZSL wrote:

this will find only first usage, but not a second.
In such case if you would have class declaration with a method in lambda, then 
it would found only this.
```
  [] {
    struct S {
      void f() {
        __func__;
      }
    };
    __func__();
  }();
```

this test is missing, other option would be to have:
```
cxxMethodDecl(isInLambda(),
                          decl().bind("fn"),
                          
hasBody(foreachDescendant(predefinedExpr(hasAncestor(cxxMethodDecl().bind("fn2")),
                                                                                
                   hasAncestor(cxxMethodDecl(equalsBoundNode("fn"), 
equalsBoundNode("fn2"))))
```

or instead of using double equalsBoundNode, you can put this code into check 
method, in such case we could avoid second hasAncestor, other option would be 
something like `hasAncestor(compoundStmt(hasParent(cxxMethodDecl...` but this 
also can be error prone, as it will skip functions in lambdas.

https://github.com/llvm/llvm-project/pull/89076
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to