diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp --- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp @@ -183,9 +183,9 @@ Param->hasAttr()) continue; - // In non-strict mode ignore function definitions with empty bodies + // In non-strict mode ignore public function definitions with empty bodies // (constructor initializer counts for non-empty body). - if (StrictMode || + if (StrictMode || !Function->isExternallyVisible() || (Function->getBody()->child_begin() != Function->getBody()->child_end()) || (isa(Function) && diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst --- a/clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst @@ -37,6 +37,8 @@ When `false` (default value), the check will ignore trivially unused parameters, i.e. when the corresponding function has an empty body (and in case of - constructors - no constructor initializers). When the function body is empty, - an unused parameter is unlikely to be unnoticed by a human reader, and - there's basically no place for a bug to hide. + constructors - no constructor initializers) and the definition is public. When + the function body is empty, an unused parameter is unlikely to be unnoticed by + a human reader, and there's basically no place for a bug to hide. On the other + hand for non-public functions, all the call-sites are visible and the parameter + can be eliminated entirely. diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc-unused-parameters.cpp @@ -154,6 +154,10 @@ namespace { class C { public: +// CHECK-FIXES: C() {} + C(int i) {} +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning + void f(int i); // CHECK-FIXES: void f(); void g(int i) {;} @@ -181,7 +185,7 @@ void useFunction(T t); void someMoreCallSites() { - C c; + C c(42); c.f(1); // CHECK-FIXES: c.f(); c.g(1);