summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2016-06-28 14:19:41 +0000
committerSamuel Benzaquen <sbenza@google.com>2016-06-28 14:19:41 +0000
commit25cd6139e3ecec7796de11b2aa9f30779f145b92 (patch)
tree1525731e6f134f7323b7adc1f484887b79d6528d
parent91bd7dda3af80f6d53988d494e481212f30b85b3 (diff)
downloadbcm5719-llvm-25cd6139e3ecec7796de11b2aa9f30779f145b92.tar.gz
bcm5719-llvm-25cd6139e3ecec7796de11b2aa9f30779f145b92.zip
[clang-tidy] Do not match on lambdas.
We match on the generated FunctionDecl of the lambda and try to fix it. This causes a crash. The right behavior is to ignore lambdas, because they are a definition. llvm-svn: 274019
-rw-r--r--clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp12
-rw-r--r--clang-tools-extra/test/clang-tidy/readability-avoid-const-params-in-decls.cpp4
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) {};
OpenPOWER on IntegriCloud