[clang-tools-extra] [clang-tidy] bugprone-lambda-function-name ignore macro in captures (PR #89076)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 18 03:40:35 PDT 2024
================
@@ -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
More information about the cfe-commits
mailing list