[PATCH] D58731: [clang-tidy] added cppcoreguidelines-explicit-virtual-functions
Lewis Clark via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 27 11:46:42 PST 2019
lewmpk created this revision.
lewmpk added reviewers: alexfh, alexfh_.
Herald added subscribers: cfe-commits, kbarton, xazax.hun, nemanjai.
Herald added a project: clang.
Addresses the bugzilla bug #30397.
modernize-use-override suggests that destructors require the override specifier and the CPP core guidelines do not recommend this.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D58731
Files:
clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
clang-tidy/modernize/UseOverrideCheck.cpp
clang-tidy/modernize/UseOverrideCheck.h
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;
+
+protected:
+ const bool IgnoreDestructors;
};
} // namespace modernize
Index: clang-tidy/modernize/UseOverrideCheck.cpp
===================================================================
--- clang-tidy/modernize/UseOverrideCheck.cpp
+++ clang-tidy/modernize/UseOverrideCheck.cpp
@@ -19,8 +19,16 @@
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;
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58731.188588.patch
Type: text/x-patch
Size: 2929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190227/6aff3ce2/attachment.bin>
More information about the cfe-commits
mailing list