diff options
author | Miklos Vajna <vmiklos@vmiklos.hu> | 2018-10-21 19:16:25 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@vmiklos.hu> | 2018-10-21 19:16:25 +0000 |
commit | beb73b3f8faf0dfa92bfb4dc896b7ffdc51770c8 (patch) | |
tree | e3bb939088a16ad2ec83e4f24c1f0bd76e12b09d /clang-tidy/readability | |
parent | 140292348233a3363602be545e91bdf864680490 (diff) |
[clang-tidy] add IgnoreMacros option to readability-redundant-smartptr-get
And also enable it by default to be consistent with e.g. modernize-use-using.
This helps e.g. when running this check on client code where the macro is
provided by the system, so there is no easy way to modify it.
Reviewed By: JonasToth
Differential Revision: https://reviews.llvm.org/D53454
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@344871 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/readability')
-rw-r--r-- | clang-tidy/readability/RedundantSmartptrGetCheck.cpp | 8 | ||||
-rw-r--r-- | clang-tidy/readability/RedundantSmartptrGetCheck.h | 7 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang-tidy/readability/RedundantSmartptrGetCheck.cpp b/clang-tidy/readability/RedundantSmartptrGetCheck.cpp index b03b546f..189130ef 100644 --- a/clang-tidy/readability/RedundantSmartptrGetCheck.cpp +++ b/clang-tidy/readability/RedundantSmartptrGetCheck.cpp @@ -91,6 +91,11 @@ void registerMatchersForGetEquals(MatchFinder *Finder, } // namespace +void RedundantSmartptrGetCheck::storeOptions( + ClangTidyOptions::OptionMap &Opts) { + Options.store(Opts, "IgnoreMacros", IgnoreMacros); +} + void RedundantSmartptrGetCheck::registerMatchers(MatchFinder *Finder) { // Only register the matchers for C++; the functionality currently does not // provide any benefit to other languages, despite being benign. @@ -126,6 +131,9 @@ void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) { bool IsPtrToPtr = Result.Nodes.getNodeAs<Decl>("ptr_to_ptr") != nullptr; bool IsMemberExpr = Result.Nodes.getNodeAs<Expr>("memberExpr") != nullptr; const auto *GetCall = Result.Nodes.getNodeAs<Expr>("redundant_get"); + if (GetCall->getBeginLoc().isMacroID() && IgnoreMacros) + return; + const auto *Smartptr = Result.Nodes.getNodeAs<Expr>("smart_pointer"); if (IsPtrToPtr && IsMemberExpr) { diff --git a/clang-tidy/readability/RedundantSmartptrGetCheck.h b/clang-tidy/readability/RedundantSmartptrGetCheck.h index 1da61958..a6f5706c 100644 --- a/clang-tidy/readability/RedundantSmartptrGetCheck.h +++ b/clang-tidy/readability/RedundantSmartptrGetCheck.h @@ -28,9 +28,14 @@ namespace readability { class RedundantSmartptrGetCheck : public ClangTidyCheck { public: RedundantSmartptrGetCheck(StringRef Name, ClangTidyContext *Context) - : ClangTidyCheck(Name, Context) {} + : ClangTidyCheck(Name, Context), + IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", 1) != 0) {} + void storeOptions(ClangTidyOptions::OptionMap &Opts) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + +private: + const bool IgnoreMacros; }; } // namespace readability |