forked from OSchip/llvm-project
Don't treat invalid parameters as being unused
The misc-unused-parameters check would trigger false positive warnings about the parameter being unused when the parameter declaration was invalid. No longer issue the warning in that case on the assumption that most parameters are used in practice, so the extra diagnostic is most likely a false positive. Fixes #56152
This commit is contained in:
parent
8958e70ccb
commit
bb297024fa
|
@ -135,6 +135,9 @@ void UnusedParametersCheck::warnOnUnusedParameter(
|
|||
const MatchFinder::MatchResult &Result, const FunctionDecl *Function,
|
||||
unsigned ParamIndex) {
|
||||
const auto *Param = Function->getParamDecl(ParamIndex);
|
||||
// Don't bother to diagnose invalid parameters as being unused.
|
||||
if (Param->isInvalidDecl())
|
||||
return;
|
||||
auto MyDiag = diag(Param->getLocation(), "parameter %0 is unused") << Param;
|
||||
|
||||
if (!Indexer) {
|
||||
|
|
|
@ -110,6 +110,9 @@ Improvements to clang-tidy
|
|||
from suppressing diagnostics associated with macro arguments. This fixes
|
||||
`Issue 55134 <https://github.com/llvm/llvm-project/issues/55134>`_.
|
||||
|
||||
- Invalid parameters are no longer treated as being implicitly unused for the
|
||||
`-misc-unused-parameters` check. This fixes `Issue 56152 <https://github.com/llvm/llvm-project/issues/56152>`_.
|
||||
|
||||
New checks
|
||||
^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// RUN: %check_clang_tidy -fix-errors %s misc-unused-parameters %t
|
||||
|
||||
namespace GH56152 {
|
||||
// There's no way to know whether the parameter is used or not if the parameter
|
||||
// is an invalid declaration. Ensure the diagnostic is suppressed in this case.
|
||||
void func(unknown_type value) { // CHECK-MESSAGES: :[[@LINE]]:11: error: unknown type name 'unknown_type'
|
||||
value += 1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue