Author: jonastoth Date: Thu Feb 28 06:55:12 2019 New Revision: 355093 URL: http://llvm.org/viewvc/llvm-project?rev=355093&view=rev Log: [clang-tidy] added cppcoreguidelines-explicit-virtual-functions
Addresses the bugzilla bug #30397. (https://bugs.llvm.org/show_bug.cgi?id=30397) modernize-use-override suggests that destructors require the override specifier and the CPP core guidelines do not recommend this. Patch by lewmpk. Differential Revision: https://reviews.llvm.org/D58731 Added: clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst clang-tools-extra/trunk/test/clang-tidy/modernize-use-override-no-destructors.cpp Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h clang-tools-extra/trunk/docs/ReleaseNotes.rst clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-override.rst Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp?rev=355093&r1=355092&r2=355093&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp Thu Feb 28 06:55:12 2019 @@ -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 @@ public: "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 @@ public: Opts["cppcoreguidelines-non-private-member-variables-in-classes." "IgnoreClassesWithAllMemberVariablesBeingPublic"] = "1"; + Opts["cppcoreguidelines-explicit-virtual-functions." + "IgnoreDestructors"] = "1"; + return Options; } }; Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp?rev=355093&r1=355092&r2=355093&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp Thu Feb 28 06:55:12 2019 @@ -17,9 +17,20 @@ namespace clang { namespace tidy { namespace modernize { +void UseOverrideCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "IgnoreDestructors", IgnoreDestructors); +} + void UseOverrideCheck::registerMatchers(MatchFinder *Finder) { // Only register the matcher for C++11. - if (getLangOpts().CPlusPlus11) + if (!getLangOpts().CPlusPlus11) + return; + + if (IgnoreDestructors) + Finder->addMatcher( + cxxMethodDecl(isOverride(), unless(cxxDestructorDecl())).bind("method"), + this); + else Finder->addMatcher(cxxMethodDecl(isOverride()).bind("method"), this); } Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h?rev=355093&r1=355092&r2=355093&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.h Thu Feb 28 06:55:12 2019 @@ -19,9 +19,14 @@ namespace modernize { 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; + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; + +private: + const bool IgnoreDestructors; }; } // namespace modernize Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=355093&r1=355092&r2=355093&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original) +++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Feb 28 06:55:12 2019 @@ -98,6 +98,11 @@ Improvements to clang-tidy Checks whether there are underscores in googletest test and test case names in test macros, which is prohibited by the Googletest FAQ. +- New alias :doc:`cppcoreguidelines-explicit-virtual-functions + <clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions>` to + :doc:`modernize-use-override + <clang-tidy/checks/modernize-use-override>` was added. + - The :doc:`bugprone-argument-comment <clang-tidy/checks/bugprone-argument-comment>` now supports `CommentBoolLiterals`, `CommentIntegerLiterals`, `CommentFloatLiterals`, Added: clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst?rev=355093&view=auto ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst (added) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/cppcoreguidelines-explicit-virtual-functions.rst Thu Feb 28 06:55:12 2019 @@ -0,0 +1,10 @@ +.. title:: clang-tidy - cppcoreguidelines-explicit-virtual-functions +.. meta:: + :http-equiv=refresh: 5;URL=cppcoreguidelines-explicit-virtual-functions.html + +cppcoreguidelines-explicit-virtual-functions +============================================ + +The cppcoreguidelines-explicit-virtual-functions check is an alias, please see +`modernize-use-override <modernize-use-override.html>`_ +for more information. Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-override.rst URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-override.rst?rev=355093&r1=355092&r2=355093&view=diff ============================================================================== --- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-override.rst (original) +++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-override.rst Thu Feb 28 06:55:12 2019 @@ -3,5 +3,11 @@ modernize-use-override ====================== - Use C++11's ``override`` and remove ``virtual`` where applicable. + +Options +------- + +.. option:: IgnoreDestructors + + If set to non-zero, this check will not diagnose destructors. Default is `0`. Added: clang-tools-extra/trunk/test/clang-tidy/modernize-use-override-no-destructors.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-override-no-destructors.cpp?rev=355093&view=auto ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/modernize-use-override-no-destructors.cpp (added) +++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-override-no-destructors.cpp Thu Feb 28 06:55:12 2019 @@ -0,0 +1,16 @@ +// 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: + virtual void f(); + // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer using + // CHECK-FIXES: {{^}} void f() override; +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits