[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
This revision was automatically updated to reflect the committed changes. Closed by commit rL307130: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique… (authored by hokein). Repository: rL LLVM https://reviews.llvm.org/D34206 Files: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-make-shared.rst clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-make-unique.rst clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared-header.cpp clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp === --- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy %s modernize-make-unique %t -- \ +// RUN: -config="{CheckOptions: \ +// RUN: [{key: modernize-make-unique.MakeSmartPtrFunction, \ +// RUN: value: 'my::MakeUnique'}, \ +// RUN: {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \ +// RUN: value: 'make_unique_util.h'} \ +// RUN: ]}" \ +// RUN: -- -std=c++11 -I%S/Inputs/modernize-smart-ptr + +#include "unique_ptr.h" +// CHECK-FIXES: #include "make_unique_util.h" + +void f() { + std::unique_ptr P1 = std::unique_ptr(new int()); + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeUnique instead + // CHECK-FIXES: std::unique_ptr P1 = my::MakeUnique(); +} Index: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h === --- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h +++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h @@ -0,0 +1,28 @@ +namespace std { + +template +class default_delete {}; + +template > +class unique_ptr { +public: + unique_ptr(); + unique_ptr(type *ptr); + unique_ptr(const unique_ptr ) = delete; + unique_ptr(unique_ptr &); + ~unique_ptr(); + type *() { return *ptr; } + type *operator->() { return ptr; } + type *release(); + void reset(); + void reset(type *pt); + void reset(type pt); + unique_ptr =(unique_ptr &&); + template + unique_ptr =(unique_ptr &&); + +private: + type *ptr; +}; + +} // namespace std Index: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h === --- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h +++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h @@ -0,0 +1,24 @@ +namespace std { + +template +class shared_ptr { +public: + shared_ptr(); + shared_ptr(type *ptr); + shared_ptr(const shared_ptr ) {} + shared_ptr(shared_ptr &) {} + ~shared_ptr(); + type *() { return *ptr; } + type *operator->() { return ptr; } + type *release(); + void reset(); + void reset(type *pt); + shared_ptr =(shared_ptr &&); + template + shared_ptr =(shared_ptr &&); + +private: + type *ptr; +}; + +} // namespace std Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp === --- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp @@ -1,32 +1,8 @@ -// RUN: %check_clang_tidy %s modernize-make-unique %t +// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr -namespace std { - -template -class default_delete {}; - -template > -class unique_ptr { -public: - unique_ptr(); - unique_ptr(type *ptr); - unique_ptr(const unique_ptr ) = delete; - unique_ptr(unique_ptr &); - ~unique_ptr(); - type *() { return *ptr; } - type *operator->() { return ptr; } - type *release(); - void reset(); - void reset(type *pt); - void reset(type pt); - unique_ptr =(unique_ptr &&); - template - unique_ptr =(unique_ptr &&); - -private: - type *ptr; -}; -} +#include "unique_ptr.h" +// CHECK-FIXES: #include struct Base { Base(); Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared-header.cpp === --- clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared-header.cpp +++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared-header.cpp @@
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
hokein updated this revision to Diff 105190. hokein marked 2 inline comments as done. hokein added a comment. Fix small nits. 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 test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h test/clang-tidy/modernize-make-shared-header.cpp test/clang-tidy/modernize-make-shared.cpp test/clang-tidy/modernize-make-unique-header.cpp test/clang-tidy/modernize-make-unique.cpp Index: test/clang-tidy/modernize-make-unique.cpp === --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -1,32 +1,8 @@ -// RUN: %check_clang_tidy %s modernize-make-unique %t +// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr -namespace std { - -template -class default_delete {}; - -template > -class unique_ptr { -public: - unique_ptr(); - unique_ptr(type *ptr); - unique_ptr(const unique_ptr ) = delete; - unique_ptr(unique_ptr &); - ~unique_ptr(); - type *() { return *ptr; } - type *operator->() { return ptr; } - type *release(); - void reset(); - void reset(type *pt); - void reset(type pt); - unique_ptr =(unique_ptr &&); - template - unique_ptr =(unique_ptr &&); - -private: - type *ptr; -}; -} +#include "unique_ptr.h" +// CHECK-FIXES: #include struct Base { Base(); Index: test/clang-tidy/modernize-make-unique-header.cpp === --- /dev/null +++ test/clang-tidy/modernize-make-unique-header.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy %s modernize-make-unique %t -- \ +// RUN: -config="{CheckOptions: \ +// RUN: [{key: modernize-make-unique.MakeSmartPtrFunction, \ +// RUN: value: 'my::MakeUnique'}, \ +// RUN: {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \ +// RUN: value: 'make_unique_util.h'} \ +// RUN: ]}" \ +// RUN: -- -std=c++11 -I%S/Inputs/modernize-smart-ptr + +#include "unique_ptr.h" +// CHECK-FIXES: #include "make_unique_util.h" + +void f() { + std::unique_ptr P1 = std::unique_ptr(new int()); + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeUnique instead + // CHECK-FIXES: std::unique_ptr P1 = my::MakeUnique(); +} Index: test/clang-tidy/modernize-make-shared.cpp === --- test/clang-tidy/modernize-make-shared.cpp +++ test/clang-tidy/modernize-make-shared.cpp @@ -1,28 +1,8 @@ -// RUN: %check_clang_tidy %s modernize-make-shared %t +// RUN: %check_clang_tidy %s modernize-make-shared %t -- -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr -namespace std { - -template -class shared_ptr { -public: - shared_ptr(); - shared_ptr(type *ptr); - shared_ptr(const shared_ptr ) {} - shared_ptr(shared_ptr &) {} - ~shared_ptr(); - type *() { return *ptr; } - type *operator->() { return ptr; } - type *release(); - void reset(); - void reset(type *pt); - shared_ptr =(shared_ptr &&); - template - shared_ptr =(shared_ptr &&); - -private: - type *ptr; -}; -} +#include "shared_ptr.h" +// CHECK-FIXES: #include struct Base { Base(); Index: test/clang-tidy/modernize-make-shared-header.cpp === --- /dev/null +++ test/clang-tidy/modernize-make-shared-header.cpp @@ -0,0 +1,17 @@ +// RUN: %check_clang_tidy %s modernize-make-shared %t -- \ +// RUN: -config="{CheckOptions: \ +// RUN: [{key: modernize-make-shared.MakeSmartPtrFunction, \ +// RUN: value: 'my::MakeShared'}, \ +// RUN: {key: modernize-make-shared.MakeSmartPtrFunctionHeader, \ +// RUN: value: 'make_shared_util.h'} \ +// RUN: ]}" \ +// RUN: -- -std=c++11 -I%S/Inputs/modernize-smart-ptr + +#include "shared_ptr.h" +// CHECK-FIXES: #include "make_shared_util.h" + +void f() { + std::shared_ptr P1 = std::shared_ptr(new int()); + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeShared instead + // CHECK-FIXES: std::shared_ptr P1 = my::MakeShared(); +} Index: test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h === --- /dev/null +++ test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h @@ -0,0 +1,28 @@ +namespace std { + +template +class default_delete {}; + +template > +class unique_ptr { +public: + unique_ptr(); + unique_ptr(type *ptr); + unique_ptr(const unique_ptr ) = delete; + unique_ptr(unique_ptr &); + ~unique_ptr(); + type *() { return *ptr; } + type *operator->() { return ptr; } + type *release(); + void reset(); + void reset(type *pt); + void reset(type pt); + unique_ptr =(unique_ptr &&); + template + unique_ptr =(unique_ptr &&);
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
alexfh accepted this revision. alexfh added a comment. This revision is now accepted and ready to land. LG with a couple of nits. Comment at: test/clang-tidy/modernize-make-shared-header.cpp:9 +// RUN: -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr + I'd put this on the previous line. Comment at: test/clang-tidy/modernize-make-unique-header.cpp:9 +// RUN: -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr + I'd put this on the previous line. https://reviews.llvm.org/D34206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
hokein added inline comments. Comment at: test/clang-tidy/modernize-make-shared-header.cpp:1 +// RUN: cp %S/Inputs/modernize-smart-ptr/shared_ptr.h %T/shared_ptr.h +// RUN: %check_clang_tidy %s modernize-make-shared %t -- \ alexfh wrote: > Maybe just add "-I%S/Inputs/modernize-smart-ptr/" flag to the clang-tidy > invocation? Good idea! https://reviews.llvm.org/D34206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
hokein updated this revision to Diff 104922. hokein marked 2 inline comments as done. hokein added a comment. Herald added a subscriber: JDevlieghere. Rebase and address review comments. 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 test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h test/clang-tidy/modernize-make-shared-header.cpp test/clang-tidy/modernize-make-shared.cpp test/clang-tidy/modernize-make-unique-header.cpp test/clang-tidy/modernize-make-unique.cpp Index: test/clang-tidy/modernize-make-unique.cpp === --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -1,32 +1,8 @@ -// RUN: %check_clang_tidy %s modernize-make-unique %t +// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr -namespace std { - -template -class default_delete {}; - -template > -class unique_ptr { -public: - unique_ptr(); - unique_ptr(type *ptr); - unique_ptr(const unique_ptr ) = delete; - unique_ptr(unique_ptr &); - ~unique_ptr(); - type *() { return *ptr; } - type *operator->() { return ptr; } - type *release(); - void reset(); - void reset(type *pt); - void reset(type pt); - unique_ptr =(unique_ptr &&); - template - unique_ptr =(unique_ptr &&); - -private: - type *ptr; -}; -} +#include "unique_ptr.h" +// CHECK-FIXES: #include struct Base { Base(); Index: test/clang-tidy/modernize-make-unique-header.cpp === --- /dev/null +++ test/clang-tidy/modernize-make-unique-header.cpp @@ -0,0 +1,18 @@ +// RUN: %check_clang_tidy %s modernize-make-unique %t -- \ +// RUN: -config="{CheckOptions: \ +// RUN: [{key: modernize-make-unique.MakeSmartPtrFunction, \ +// RUN: value: 'my::MakeUnique'}, \ +// RUN: {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \ +// RUN: value: 'make_unique_util.h'} \ +// RUN: ]}" \ +// RUN: -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr + +#include "unique_ptr.h" +// CHECK-FIXES: #include "make_unique_util.h" + +void f() { + std::unique_ptr P1 = std::unique_ptr(new int()); + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeUnique instead + // CHECK-FIXES: std::unique_ptr P1 = my::MakeUnique(); +} Index: test/clang-tidy/modernize-make-shared.cpp === --- test/clang-tidy/modernize-make-shared.cpp +++ test/clang-tidy/modernize-make-shared.cpp @@ -1,28 +1,8 @@ -// RUN: %check_clang_tidy %s modernize-make-shared %t +// RUN: %check_clang_tidy %s modernize-make-shared %t -- -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr -namespace std { - -template -class shared_ptr { -public: - shared_ptr(); - shared_ptr(type *ptr); - shared_ptr(const shared_ptr ) {} - shared_ptr(shared_ptr &) {} - ~shared_ptr(); - type *() { return *ptr; } - type *operator->() { return ptr; } - type *release(); - void reset(); - void reset(type *pt); - shared_ptr =(shared_ptr &&); - template - shared_ptr =(shared_ptr &&); - -private: - type *ptr; -}; -} +#include "shared_ptr.h" +// CHECK-FIXES: #include struct Base { Base(); Index: test/clang-tidy/modernize-make-shared-header.cpp === --- /dev/null +++ test/clang-tidy/modernize-make-shared-header.cpp @@ -0,0 +1,18 @@ +// RUN: %check_clang_tidy %s modernize-make-shared %t -- \ +// RUN: -config="{CheckOptions: \ +// RUN: [{key: modernize-make-shared.MakeSmartPtrFunction, \ +// RUN: value: 'my::MakeShared'}, \ +// RUN: {key: modernize-make-shared.MakeSmartPtrFunctionHeader, \ +// RUN: value: 'make_shared_util.h'} \ +// RUN: ]}" \ +// RUN: -- -std=c++11 \ +// RUN: -I%S/Inputs/modernize-smart-ptr + +#include "shared_ptr.h" +// CHECK-FIXES: #include "make_shared_util.h" + +void f() { + std::shared_ptr P1 = std::shared_ptr(new int()); + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeShared instead + // CHECK-FIXES: std::shared_ptr P1 = my::MakeShared(); +} Index: test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h === --- /dev/null +++ test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h @@ -0,0 +1,28 @@ +namespace std { + +template +class default_delete {}; + +template > +class unique_ptr { +public: + unique_ptr(); + unique_ptr(type *ptr); + unique_ptr(const unique_ptr ) = delete; + unique_ptr(unique_ptr &); + ~unique_ptr(); + type *() { return *ptr; } + type *operator->() { return ptr; } + type *release(); + void reset(); + void reset(type *pt); + void
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
alexfh requested changes to this revision. alexfh added inline comments. This revision now requires changes to proceed. Comment at: clang-tidy/modernize/MakeSmartPtrCheck.h:28 MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, -std::string makeSmartPtrFunctionName); +StringRef makeSmartPtrFunctionName); void registerMatchers(ast_matchers::MatchFinder *Finder) final; s/makeSmartPtr/MakeSmartPtr/ here and below. Comment at: test/clang-tidy/modernize-make-shared-header.cpp:1 +// RUN: cp %S/Inputs/modernize-smart-ptr/shared_ptr.h %T/shared_ptr.h +// RUN: %check_clang_tidy %s modernize-make-shared %t -- \ Maybe just add "-I%S/Inputs/modernize-smart-ptr/" flag to the clang-tidy invocation? https://reviews.llvm.org/D34206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
hokein added a comment. In https://reviews.llvm.org/D34206#790406, @alexfh wrote: > Ping me once you're done fixing the bugs. The bugs are fixed. The patch is ready for review ;) https://reviews.llvm.org/D34206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
hokein added a comment. In https://reviews.llvm.org/D34206#790406, @alexfh wrote: > In https://reviews.llvm.org/D34206#783673, @hokein wrote: > > > In https://reviews.llvm.org/D34206#780455, @Eugene.Zelenko wrote: > > > > > It'll be good idea to run modernize-make-unique on LLVM/Clang/etc for > > > llvm::make_unique. > > > > > > +1. See https://reviews.llvm.org/D34334, https://reviews.llvm.org/D34333. > > And found a few bugs in the check, will work on fixes on them. > > > Ping me once you're done fixing the bugs. I have a fix patch under review: https://reviews.llvm.org/D34286, and the other will come afterwards. I think it is fine to check in this patch before these two bugs are fixed. https://reviews.llvm.org/D34206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
alexfh added a comment. In https://reviews.llvm.org/D34206#783673, @hokein wrote: > In https://reviews.llvm.org/D34206#780455, @Eugene.Zelenko wrote: > > > It'll be good idea to run modernize-make-unique on LLVM/Clang/etc for > > llvm::make_unique. > > > +1. See https://reviews.llvm.org/D34334, https://reviews.llvm.org/D34333. And > found a few bugs in the check, will work on fixes on them. Ping me once you're done fixing the bugs. https://reviews.llvm.org/D34206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
hokein added a comment. In https://reviews.llvm.org/D34206#780455, @Eugene.Zelenko wrote: > It'll be good idea to run modernize-make-unique on LLVM/Clang/etc for > llvm::make_unique. +1. See https://reviews.llvm.org/D34334, https://reviews.llvm.org/D34333. And found a few bugs in the check, will work on fixes on them. https://reviews.llvm.org/D34206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
hokein updated this revision to Diff 102833. hokein added a comment. More improvements. 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 test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h test/clang-tidy/modernize-make-shared-header.cpp test/clang-tidy/modernize-make-shared.cpp test/clang-tidy/modernize-make-unique-header.cpp test/clang-tidy/modernize-make-unique.cpp Index: test/clang-tidy/modernize-make-unique.cpp === --- test/clang-tidy/modernize-make-unique.cpp +++ test/clang-tidy/modernize-make-unique.cpp @@ -1,31 +1,8 @@ +// RUN: cp %S/Inputs/modernize-smart-ptr/unique_ptr.h %T/unique_ptr.h // RUN: %check_clang_tidy %s modernize-make-unique %t -namespace std { - -template -class default_delete {}; - -template > -class unique_ptr { -public: - unique_ptr(); - unique_ptr(type *ptr); - unique_ptr(const unique_ptr ) = delete; - unique_ptr(unique_ptr &); - ~unique_ptr(); - type *() { return *ptr; } - type *operator->() { return ptr; } - type *release(); - void reset(); - void reset(type *pt); - unique_ptr =(unique_ptr &&); - template - unique_ptr =(unique_ptr &&); - -private: - type *ptr; -}; -} +#include "unique_ptr.h" +// CHECK-FIXES: #include struct Base { Base(); Index: test/clang-tidy/modernize-make-unique-header.cpp === --- /dev/null +++ test/clang-tidy/modernize-make-unique-header.cpp @@ -0,0 +1,18 @@ +// RUN: cp %S/Inputs/modernize-smart-ptr/unique_ptr.h %T/unique_ptr.h +// RUN: %check_clang_tidy %s modernize-make-unique %t -- \ +// RUN: -config="{CheckOptions: \ +// RUN: [{key: modernize-make-unique.MakeSmartPtrFunction, \ +// RUN: value: 'my::MakeUnique'}, \ +// RUN: {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \ +// RUN: value: 'make_unique_util.h'} \ +// RUN: ]}" \ +// RUN: -- -std=c++11 + +#include "unique_ptr.h" +// CHECK-FIXES: #include "make_unique_util.h" + +void f() { + std::unique_ptr P1 = std::unique_ptr(new int()); + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeUnique instead + // CHECK-FIXES: std::unique_ptr P1 = my::MakeUnique(); +} Index: test/clang-tidy/modernize-make-shared.cpp === --- test/clang-tidy/modernize-make-shared.cpp +++ test/clang-tidy/modernize-make-shared.cpp @@ -1,28 +1,8 @@ +// RUN: cp %S/Inputs/modernize-smart-ptr/shared_ptr.h %T/shared_ptr.h // RUN: %check_clang_tidy %s modernize-make-shared %t -namespace std { - -template -class shared_ptr { -public: - shared_ptr(); - shared_ptr(type *ptr); - shared_ptr(const shared_ptr ) {} - shared_ptr(shared_ptr &) {} - ~shared_ptr(); - type *() { return *ptr; } - type *operator->() { return ptr; } - type *release(); - void reset(); - void reset(type *pt); - shared_ptr =(shared_ptr &&); - template - shared_ptr =(shared_ptr &&); - -private: - type *ptr; -}; -} +#include "shared_ptr.h" +// CHECK-FIXES: #include struct Base { Base(); Index: test/clang-tidy/modernize-make-shared-header.cpp === --- /dev/null +++ test/clang-tidy/modernize-make-shared-header.cpp @@ -0,0 +1,18 @@ +// RUN: cp %S/Inputs/modernize-smart-ptr/shared_ptr.h %T/shared_ptr.h +// RUN: %check_clang_tidy %s modernize-make-shared %t -- \ +// RUN: -config="{CheckOptions: \ +// RUN: [{key: modernize-make-shared.MakeSmartPtrFunction, \ +// RUN: value: 'my::MakeShared'}, \ +// RUN: {key: modernize-make-shared.MakeSmartPtrFunctionHeader, \ +// RUN: value: 'make_shared_util.h'} \ +// RUN: ]}" \ +// RUN: -- -std=c++11 + +#include "shared_ptr.h" +// CHECK-FIXES: #include "make_shared_util.h" + +void f() { + std::shared_ptr P1 = std::shared_ptr(new int()); + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeShared instead + // CHECK-FIXES: std::shared_ptr P1 = my::MakeShared(); +} Index: test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h === --- /dev/null +++ test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h @@ -0,0 +1,27 @@ +namespace std { + +template +class default_delete {}; + +template > +class unique_ptr { +public: + unique_ptr(); + unique_ptr(type *ptr); + unique_ptr(const unique_ptr ) = delete; + unique_ptr(unique_ptr &); + ~unique_ptr(); + type *() { return *ptr; } + type *operator->() { return ptr; } + type *release(); + void reset(); + void reset(type *pt); + unique_ptr =(unique_ptr &&); + template + unique_ptr =(unique_ptr &&); + +private: + type *ptr; +}; + +} // namespace std Index:
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
Eugene.Zelenko added a comment. It'll be good idea to run modernize-make-unique on LLVM/Clang/etc for llvm::make_unique. https://reviews.llvm.org/D34206 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.
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(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(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 ) final; + void storeOptions(ClangTidyOptions::OptionMap ) override; protected: using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher; 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 ) { + Options.store(Opts, "MakeSmartPtrFunction", makeSmartPtrFunctionName); +} void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) { if (!getLangOpts().CPlusPlus11) 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(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(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 ) final; + void storeOptions(ClangTidyOptions::OptionMap ) override; protected: using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher; Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp === --- clang-tidy/modernize/MakeSmartPtrCheck.cpp +++