diff options
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp | 12 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/readability-avoid-const-params-in-decls.cpp | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp index 6e68dda945b..11a588310f8 100644 --- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp +++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp @@ -32,10 +32,14 @@ SourceRange getTypeRange(const ParmVarDecl &Param) { void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) { const auto ConstParamDecl = parmVarDecl(hasType(qualType(isConstQualified()))).bind("param"); - Finder->addMatcher(functionDecl(unless(isDefinition()), - has(typeLoc(forEach(ConstParamDecl)))) - .bind("func"), - this); + Finder->addMatcher( + functionDecl(unless(isDefinition()), + // Lambdas are always their own definition, but they + // generate a non-definition FunctionDecl too. Ignore those. + unless(cxxMethodDecl(ofClass(cxxRecordDecl(isLambda())))), + has(typeLoc(forEach(ConstParamDecl)))) + .bind("func"), + this); } // Re-lex the tokens to get precise location of last 'const' diff --git a/clang-tools-extra/test/clang-tidy/readability-avoid-const-params-in-decls.cpp b/clang-tools-extra/test/clang-tidy/readability-avoid-const-params-in-decls.cpp index ef0f4bdded8..f009f9f5941 100644 --- a/clang-tools-extra/test/clang-tidy/readability-avoid-const-params-in-decls.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-avoid-const-params-in-decls.cpp @@ -90,3 +90,7 @@ void ConstNotVisible(CONCAT(cons, t) int i); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: parameter 'i' // We warn, but we can't give a fix // CHECK-FIXES: void ConstNotVisible(CONCAT(cons, t) int i); + +// Regression test. We should not warn (or crash) on lambda expressions +auto lambda_with_name = [](const int n) {}; +auto lambda_without_name = [](const int) {}; |