forked from OSchip/llvm-project
misc-unused-parameters: Fix bug where the check was looking at
ParmVarDecls of function types. llvm-svn: 243026
This commit is contained in:
parent
830f0c4c46
commit
1c6fc3b8f0
|
@ -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);
|
||||
|
|
|
@ -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); }
|
||||
|
|
Loading…
Reference in New Issue