Skip to content

Commit bb29702

Browse files
committed
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 llvm#56152
1 parent 8958e70 commit bb29702

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ void UnusedParametersCheck::warnOnUnusedParameter(
135135
const MatchFinder::MatchResult &Result, const FunctionDecl *Function,
136136
unsigned ParamIndex) {
137137
const auto *Param = Function->getParamDecl(ParamIndex);
138+
// Don't bother to diagnose invalid parameters as being unused.
139+
if (Param->isInvalidDecl())
140+
return;
138141
auto MyDiag = diag(Param->getLocation(), "parameter %0 is unused") << Param;
139142

140143
if (!Indexer) {

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ Improvements to clang-tidy
110110
from suppressing diagnostics associated with macro arguments. This fixes
111111
`Issue 55134 <https://github.com/llvm/llvm-project/issues/55134>`_.
112112

113+
- Invalid parameters are no longer treated as being implicitly unused for the
114+
`-misc-unused-parameters` check. This fixes `Issue 56152 <https://github.com/llvm/llvm-project/issues/56152>`_.
115+
113116
New checks
114117
^^^^^^^^^^
115118

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %check_clang_tidy -fix-errors %s misc-unused-parameters %t
2+
3+
namespace GH56152 {
4+
// There's no way to know whether the parameter is used or not if the parameter
5+
// is an invalid declaration. Ensure the diagnostic is suppressed in this case.
6+
void func(unknown_type value) { // CHECK-MESSAGES: :[[@LINE]]:11: error: unknown type name 'unknown_type'
7+
value += 1;
8+
}
9+
}
10+

0 commit comments

Comments
 (0)