[clang-tools-extra] bb29702 - Don't treat invalid parameters as being unused
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 22 05:56:48 PDT 2022
Author: Aaron Ballman
Date: 2022-06-22T08:56:38-04:00
New Revision: bb297024fad2f6c3ccaaa6a5c3a270f73f15f3ac
URL: https://github.com/llvm/llvm-project/commit/bb297024fad2f6c3ccaaa6a5c3a270f73f15f3ac
DIFF: https://github.com/llvm/llvm-project/commit/bb297024fad2f6c3ccaaa6a5c3a270f73f15f3ac.diff
LOG: 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
Added:
clang-tools-extra/test/clang-tidy/checkers/misc-unused-invalid-parameter.cpp
Modified:
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
index 149d63ff1e62f..669132024af77 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 1f1c4c87112aa..7a660c0230cbe 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 <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
^^^^^^^^^^
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 0000000000000..e7642e79b1a47
--- /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;
+}
+}
+
More information about the cfe-commits
mailing list