[clang-tools-extra] r245048 - misc-unused-parameters: Fix crasher with C forward declarations that
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 14 06:39:57 PDT 2015
Author: djasper
Date: Fri Aug 14 08:39:57 2015
New Revision: 245048
URL: http://llvm.org/viewvc/llvm-project?rev=245048&view=rev
Log:
misc-unused-parameters: Fix crasher with C forward declarations that
can leave out the parameter list.
Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
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=245048&r1=245047&r2=245048&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedParametersCheck.cpp Fri Aug 14 08:39:57 2015
@@ -84,7 +84,8 @@ void UnusedParametersCheck::warnOnUnused
// Fix all redeclarations.
for (const FunctionDecl *FD : Function->redecls())
- MyDiag << removeParameter(FD, ParamIndex);
+ if (FD->param_size())
+ MyDiag << removeParameter(FD, ParamIndex);
// Fix all call sites.
auto CallMatches = ast_matchers::match(
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c?rev=245048&r1=245047&r2=245048&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-unused-parameters.c Fri Aug 14 08:39:57 2015
@@ -7,6 +7,11 @@ void a(int i) {}
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
// CHECK-FIXES: {{^}}void a(int /*i*/) {}{{$}}
+static void b(); // In C, forward declarations can leave out parameters.
+static void b(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: parameter 'i' is unused [misc-unused-parameters]
+// CHECK-FIXES: {{^}}static void b() {}{{$}}
+
// Unchanged cases
// ===============
void h(i, c, d) int i; char *c, *d; {} // Don't mess with K&R style
More information about the cfe-commits
mailing list