misc-unused-parameters: Fix bug where the check was looking at

ParmVarDecls of function types.

llvm-svn: 243026
This commit is contained in:
Daniel Jasper 2015-07-23 17:26:36 +00:00
parent 830f0c4c46
commit 1c6fc3b8f0
2 changed files with 6 additions and 2 deletions

View File

@ -18,7 +18,7 @@ namespace tidy {
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 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) {
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 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) {
// 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);

View File

@ -99,3 +99,5 @@ template <typename T> void someFunctionTemplateAllUnusedParams(T b, T e) {}
// CHECK-MESSAGES: :[[@LINE-1]]:66: warning
// CHECK-MESSAGES: :[[@LINE-2]]:71: warning
// CHECK-FIXES: {{^}}template <typename T> void someFunctionTemplateAllUnusedParams(T /*b*/, T /*e*/) {}
static void dontGetConfusedByParametersInFunctionTypes() { void (*F)(int i); }