lewmpk updated this revision to Diff 188622.
lewmpk marked an inline comment as done.
lewmpk added a comment.

- addressed comments
- provided tests
- updated documentation
- updated release notes




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58731/new/

https://reviews.llvm.org/D58731

Files:
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/modernize/UseOverrideCheck.cpp
  clang-tidy/modernize/UseOverrideCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-override.rst
  test/clang-tidy/modernize-use-override-no-destructors.cpp

Index: test/clang-tidy/modernize-use-override-no-destructors.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/modernize-use-override-no-destructors.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s modernize-use-override %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-override.IgnoreDestructors, value: '1'" \
+// RUN: -- -std=c++11
+
+struct Base {
+  virtual ~Base(){};
+  virtual void f(){};
+};
+
+struct Simple : public Base {
+  virtual ~Simple();
+  // CHECK-MESSAGES-NOT: warning:
+  // CHECK-FIXES: {{^}}  void b() override;
+  virtual void f(){};
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
+  // CHECK-FIXES: {{^}}  void f() override;
+};
Index: docs/clang-tidy/checks/modernize-use-override.rst
===================================================================
--- docs/clang-tidy/checks/modernize-use-override.rst
+++ docs/clang-tidy/checks/modernize-use-override.rst
@@ -5,3 +5,11 @@
 
 
 Use C++11's ``override`` and remove ``virtual`` where applicable.
+
+Options
+-------
+
+.. option:: IgnoreDestructors
+
+   If set to non-zero, this check with not diagnose destructors. Default is '0'.
+   
\ No newline at end of file
Index: docs/ReleaseNotes.rst
===================================================================
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -67,6 +67,11 @@
 Improvements to clang-tidy
 --------------------------
 
+- New :doc:`cppcoreguidelines-explicit-virtual-functions
+  <clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions>` check.
+
+  Checks whether virtual functions other than destructors can specify 'override' instead.
+
 - New :doc:`abseil-duration-addition
   <clang-tidy/checks/abseil-duration-addition>` check.
 
Index: clang-tidy/modernize/UseOverrideCheck.h
===================================================================
--- clang-tidy/modernize/UseOverrideCheck.h
+++ clang-tidy/modernize/UseOverrideCheck.h
@@ -19,9 +19,13 @@
 class UseOverrideCheck : public ClangTidyCheck {
 public:
   UseOverrideCheck(StringRef Name, ClangTidyContext *Context)
-      : ClangTidyCheck(Name, Context) {}
+      : ClangTidyCheck(Name, Context),
+        IgnoreDestructors(Options.get("IgnoreDestructors", false)) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  const bool IgnoreDestructors;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/UseOverrideCheck.cpp
===================================================================
--- clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tidy/modernize/UseOverrideCheck.cpp
@@ -19,8 +19,15 @@
 
 void UseOverrideCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matcher for C++11.
-  if (getLangOpts().CPlusPlus11)
-    Finder->addMatcher(cxxMethodDecl(isOverride()).bind("method"), this);
+  if (getLangOpts().CPlusPlus11) {
+    if (IgnoreDestructors)
+      Finder->addMatcher(
+          cxxMethodDecl(isOverride(), unless(cxxDestructorDecl()))
+              .bind("method"),
+          this);
+    else
+      Finder->addMatcher(cxxMethodDecl(isOverride()).bind("method"), this);
+  }
 }
 
 // Re-lex the tokens to get precise locations to insert 'override' and remove
Index: clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/UseOverrideCheck.h"
 #include "../readability/MagicNumbersCheck.h"
 #include "AvoidGotoCheck.h"
 #include "InterfacesGlobalInitCheck.h"
@@ -46,6 +47,8 @@
         "cppcoreguidelines-avoid-goto");
     CheckFactories.registerCheck<readability::MagicNumbersCheck>(
         "cppcoreguidelines-avoid-magic-numbers");
+    CheckFactories.registerCheck<modernize::UseOverrideCheck>(
+        "cppcoreguidelines-explicit-virtual-functions");
     CheckFactories.registerCheck<InterfacesGlobalInitCheck>(
         "cppcoreguidelines-interfaces-global-init");
     CheckFactories.registerCheck<MacroUsageCheck>(
@@ -91,6 +94,9 @@
     Opts["cppcoreguidelines-non-private-member-variables-in-classes."
          "IgnoreClassesWithAllMemberVariablesBeingPublic"] = "1";
 
+    Opts["cppcoreguidelines-explicit-virtual-functions."
+         "IgnoreDestructors"] = "1";
+
     return Options;
   }
 };
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to