[PATCH] D11417: Fix misc-unused-parameters handling of function templates

Scott Wallace scottwallace.dev at gmail.com
Wed Jul 22 07:36:45 PDT 2015


swallace created this revision.
swallace added reviewers: djasper, chandlerc.
swallace added a subscriber: cfe-commits.

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.

http://reviews.llvm.org/D11417

Files:
  clang-tidy/misc/UnusedParametersCheck.cpp
  test/clang-tidy/misc-unused-parameters.cpp

Index: test/clang-tidy/misc-unused-parameters.cpp
===================================================================
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -88,3 +88,5 @@
 }
 
 } // end namespace
+
+template <typename T> void someFunctionTemplate(T b, T e) { (void)b; (void)e; }
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -59,7 +59,8 @@
   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 @@
 
 } // namespace tidy
 } // namespace clang
-


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11417.30352.patch
Type: text/x-patch
Size: 983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150722/6d388cde/attachment.bin>


More information about the cfe-commits mailing list