misc-unused-parameters: Fix crasher with C forward declarations that

can leave out the parameter list.

llvm-svn: 245048
This commit is contained in:
Daniel Jasper 2015-08-14 13:39:57 +00:00
parent 90eb70c8a7
commit ea223a7a6a
2 changed files with 7 additions and 1 deletions

View File

@ -84,7 +84,8 @@ void UnusedParametersCheck::warnOnUnusedParameter(
// 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(

View File

@ -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