misc-unused-parameters: Fix handling of parameters in template functions.

The parameters of the function templates were being marked as
incorrectly be marked as unused. Added a test for this and changed the
check to use the same

  isReferenced() || !getDeclName()

logic as Sema::DiagnoseUnusedParameters.
Patch Scott Wallace, thank you!

llvm-svn: 242912
This commit is contained in:
Daniel Jasper 2015-07-22 17:30:35 +00:00
parent 2c674d347e
commit 9b46e9c5de
2 changed files with 13 additions and 2 deletions

View File

@ -59,7 +59,8 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) {
if (!Function->doesThisDeclarationHaveABody())
return;
const auto *Param = Result.Nodes.getNodeAs<ParmVarDecl>("x");
if (Param->isUsed())
if (Param->isUsed() || Param->isReferenced() || !Param->getDeclName() ||
Param->hasAttr<UnusedAttr>())
return;
auto MyDiag = diag(Param->getLocation(), "parameter '%0' is unused")
@ -102,4 +103,3 @@ void UnusedParametersCheck::check(const MatchFinder::MatchResult &Result) {
} // namespace tidy
} // namespace clang

View File

@ -88,3 +88,14 @@ void someMoreCallSites() {
}
} // end namespace
template <typename T> void someFunctionTemplate(T b, T e) { (void)b; (void)e; }
template <typename T> void someFunctionTemplateOneUnusedParam(T b, T e) { (void)e; }
// CHECK-MESSAGES: :[[@LINE-1]]:65: warning
// CHECK-FIXES: {{^}}template <typename T> void someFunctionTemplateOneUnusedParam(T /*b*/, T e) { (void)e; }
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*/) {}