diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp index 149d63ff1e62fa..669132024af773 100644 --- a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp @@ -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) { diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 1f1c4c87112aa2..7a660c0230cbe4 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -110,6 +110,9 @@ Improvements to clang-tidy from suppressing diagnostics associated with macro arguments. This fixes `Issue 55134 `_. +- Invalid parameters are no longer treated as being implicitly unused for the + `-misc-unused-parameters` check. This fixes `Issue 56152 `_. + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc-unused-invalid-parameter.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc-unused-invalid-parameter.cpp new file mode 100644 index 00000000000000..e7642e79b1a474 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/misc-unused-invalid-parameter.cpp @@ -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; +} +} +