[PATCH] D147918: [clang-tidy] Added IgnoreVirtual option to misc-unused-parameters
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 10 07:56:14 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG225d255a583e: [clang-tidy] Added IgnoreVirtual option to misc-unused-parameters (authored by PiotrZSL).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147918/new/
https://reviews.llvm.org/D147918
Files:
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst
clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-virtual.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-virtual.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/unused-parameters-virtual.cpp
@@ -0,0 +1,20 @@
+// RUN: %check_clang_tidy %s misc-unused-parameters %t -- \
+// RUN: -config="{CheckOptions: [{key: misc-unused-parameters.IgnoreVirtual, value: true}]}" --
+
+struct Base {
+ int f(int foo) {
+ // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'foo' is unused [misc-unused-parameters]
+ // CHECK-FIXES: int f(int /*foo*/) {
+ return 5;
+ }
+
+ virtual int f2(int foo) {
+ return 5;
+ }
+};
+
+struct Derived : Base {
+ int f2(int foo) override {
+ return 5;
+ }
+};
Index: clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst
===================================================================
--- clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc/unused-parameters.rst
@@ -40,3 +40,8 @@
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.
+
+.. option:: IgnoreVirtual
+
+ Determines whether virtual method parameters should be inspected.
+ Set to `true` to ignore them. Default is `false`.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -220,6 +220,10 @@
<clang-tidy/checks/misc/definitions-in-headers>` to avoid warning on
declarations inside anonymous namespaces.
+- Improved :doc:`misc-unused-parameters
+ <clang-tidy/checks/misc/unused-parameters>` check with new `IgnoreVirtual`
+ option to optionally ignore virtual methods.
+
- Deprecated check-local options `HeaderFileExtensions`
in :doc:`misc-unused-using-decls
<clang-tidy/checks/misc/unused-using-decls>` check.
Index: clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h
+++ clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.h
@@ -25,6 +25,7 @@
private:
const bool StrictMode;
+ const bool IgnoreVirtual;
class IndexerVisitor;
std::unique_ptr<IndexerVisitor> Indexer;
Index: clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
@@ -123,10 +123,12 @@
UnusedParametersCheck::UnusedParametersCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
- StrictMode(Options.getLocalOrGlobal("StrictMode", false)) {}
+ StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+ IgnoreVirtual(Options.get("IgnoreVirtual", false)) {}
void UnusedParametersCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "StrictMode", StrictMode);
+ Options.store(Opts, "IgnoreVirtual", IgnoreVirtual);
}
void UnusedParametersCheck::warnOnUnusedParameter(
@@ -176,9 +178,12 @@
const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("function");
if (!Function->hasWrittenPrototype() || Function->isTemplateInstantiation())
return;
- if (const auto *Method = dyn_cast<CXXMethodDecl>(Function))
+ if (const auto *Method = dyn_cast<CXXMethodDecl>(Function)) {
+ if (IgnoreVirtual && Method->isVirtual())
+ return;
if (Method->isLambdaStaticInvoker())
return;
+ }
for (unsigned I = 0, E = Function->getNumParams(); I != E; ++I) {
const auto *Param = Function->getParamDecl(I);
if (Param->isUsed() || Param->isReferenced() || !Param->getDeclName() ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147918.512148.patch
Type: text/x-patch
Size: 4037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230410/4eb586bc/attachment.bin>
More information about the cfe-commits
mailing list