[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 14 08:28:13 PDT 2017
hokein created this revision.
Herald added a subscriber: xazax.hun.
https://reviews.llvm.org/D34206
Files:
clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tidy/modernize/MakeSmartPtrCheck.h
docs/clang-tidy/checks/modernize-make-shared.rst
docs/clang-tidy/checks/modernize-make-unique.rst
Index: docs/clang-tidy/checks/modernize-make-unique.rst
===================================================================
--- docs/clang-tidy/checks/modernize-make-unique.rst
+++ docs/clang-tidy/checks/modernize-make-unique.rst
@@ -25,3 +25,11 @@
// becomes
my_ptr = std::make_unique<MyPair>(1, 2);
+
+Options
+-------
+
+.. option:: MakeSmartPtrFunction
+
+ A string specifying the name of make-unique-ptr function. Default is
+ `std::make_unique`.
Index: docs/clang-tidy/checks/modernize-make-shared.rst
===================================================================
--- docs/clang-tidy/checks/modernize-make-shared.rst
+++ docs/clang-tidy/checks/modernize-make-shared.rst
@@ -25,3 +25,11 @@
// becomes
my_ptr = std::make_shared<MyPair>(1, 2);
+
+Options
+-------
+
+.. option:: MakeSmartPtrFunction
+
+ A string specifying the name of make-shared-ptr function. Default is
+ `std::make_shared`.
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===================================================================
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -24,9 +24,10 @@
class MakeSmartPtrCheck : public ClangTidyCheck {
public:
MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
- std::string makeSmartPtrFunctionName);
+ StringRef makeSmartPtrFunctionName);
void registerMatchers(ast_matchers::MatchFinder *Finder) final;
void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
+ void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
protected:
using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher<QualType>;
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -21,10 +21,17 @@
const char MakeSmartPtrCheck::ResetCall[] = "resetCall";
const char MakeSmartPtrCheck::NewExpression[] = "newExpression";
-MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
- std::string makeSmartPtrFunctionName)
+MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name,
+ ClangTidyContext* Context,
+ StringRef makeSmartPtrFunctionName)
: ClangTidyCheck(Name, Context),
- makeSmartPtrFunctionName(std::move(makeSmartPtrFunctionName)) {}
+ makeSmartPtrFunctionName(
+ Options.get("MakeSmartPtrFunction", makeSmartPtrFunctionName)) {}
+
+void MakeSmartPtrCheck::storeOptions(
+ ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "MakeSmartPtrFunction", makeSmartPtrFunctionName);
+}
void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
if (!getLangOpts().CPlusPlus11)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34206.102552.patch
Type: text/x-patch
Size: 2903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170614/4071b12a/attachment.bin>
More information about the cfe-commits
mailing list