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
-


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
-
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to