diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp index 326fb0595e06..15c582bc5672 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp @@ -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( diff --git a/clang-tools-extra/test/clang-tidy/misc-unused-parameters.c b/clang-tools-extra/test/clang-tidy/misc-unused-parameters.c index 7c1ab34b7b58..1b04ece455b4 100644 --- a/clang-tools-extra/test/clang-tidy/misc-unused-parameters.c +++ b/clang-tools-extra/test/clang-tidy/misc-unused-parameters.c @@ -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