PiotrZSL updated this revision to Diff 512122.
PiotrZSL marked 6 inline comments as done.
PiotrZSL added a comment.

Review fixes


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() ||


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() ||
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to