misc-unused-parameters: Fix bug where the check was looking at
ParmVarDecls of function types.
llvm-svn: 243026
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
index 8449eaf..df00c9f 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -18,7 +18,7 @@
void UnusedParametersCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
- parmVarDecl(hasAncestor(functionDecl().bind("function"))).bind("x"),
+ parmVarDecl(hasParent(functionDecl().bind("function"))).bind("x"),
this);
}
@@ -60,7 +60,7 @@
return;
const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>("x");
if (Param->isUsed() || Param->isReferenced() || !Param->getDeclName() ||
- Param->hasAttr<UnusedAttr>())
+ Param->hasAttr<UnusedAttr>())
return;
auto MyDiag = diag(Param->getLocation(), "parameter '%0' is unused")
@@ -88,6 +88,8 @@
// Handle local functions by deleting the parameters.
unsigned ParamIndex = Param->getFunctionScopeIndex();
+ assert(ParamIndex < Function->getNumParams());
+
// Fix all redeclarations.
for (const FunctionDecl *FD : Function->redecls())
MyDiag << removeParameter(FD, ParamIndex);