[clang-tools-extra] r243026 - misc-unused-parameters: Fix bug where the check was looking at
Daniel Jasper
djasper at google.com
Thu Jul 23 10:26:36 PDT 2015
Author: djasper
Date: Thu Jul 23 12:26:36 2015
New Revision: 243026
URL: http://llvm.org/viewvc/llvm-project?rev=243026&view=rev
Log:
misc-unused-parameters: Fix bug where the check was looking at
ParmVarDecls of function types.
Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp?rev=243026&r1=243025&r2=243026&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp Thu Jul 23 12:26:36 2015
@@ -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
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
// 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);
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp?rev=243026&r1=243025&r2=243026&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.cpp Thu Jul 23 12:26:36 2015
@@ -99,3 +99,5 @@ template <typename T> void someFunctionT
// 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); }
More information about the cfe-commits
mailing list