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
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")
} // namespace tidy
} // namespace clang
-
}
} // 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*/) {}