-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shar…
…ed/unique checks. Reviewers: alexfh, aaron.ballman Reviewed By: alexfh Subscribers: JDevlieghere, Eugene.Zelenko, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34206 llvm-svn: 307130
- Loading branch information
Showing
10 changed files
with
184 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
clang-tools-extra/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| namespace std { | ||
|
|
||
| template <typename type> | ||
| class shared_ptr { | ||
| public: | ||
| shared_ptr(); | ||
| shared_ptr(type *ptr); | ||
| shared_ptr(const shared_ptr<type> &t) {} | ||
| shared_ptr(shared_ptr<type> &&t) {} | ||
| ~shared_ptr(); | ||
| type &operator*() { return *ptr; } | ||
| type *operator->() { return ptr; } | ||
| type *release(); | ||
| void reset(); | ||
| void reset(type *pt); | ||
| shared_ptr &operator=(shared_ptr &&); | ||
| template <typename T> | ||
| shared_ptr &operator=(shared_ptr<T> &&); | ||
|
|
||
| private: | ||
| type *ptr; | ||
| }; | ||
|
|
||
| } // namespace std |
28 changes: 28 additions & 0 deletions
28
clang-tools-extra/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| namespace std { | ||
|
|
||
| template <typename T> | ||
| class default_delete {}; | ||
|
|
||
| template <typename type, typename Deleter = std::default_delete<type>> | ||
| class unique_ptr { | ||
| public: | ||
| unique_ptr(); | ||
| unique_ptr(type *ptr); | ||
| unique_ptr(const unique_ptr<type> &t) = delete; | ||
| unique_ptr(unique_ptr<type> &&t); | ||
| ~unique_ptr(); | ||
| type &operator*() { return *ptr; } | ||
| type *operator->() { return ptr; } | ||
| type *release(); | ||
| void reset(); | ||
| void reset(type *pt); | ||
| void reset(type pt); | ||
| unique_ptr &operator=(unique_ptr &&); | ||
| template <typename T> | ||
| unique_ptr &operator=(unique_ptr<T> &&); | ||
|
|
||
| private: | ||
| type *ptr; | ||
| }; | ||
|
|
||
| } // namespace std |
17 changes: 17 additions & 0 deletions
17
clang-tools-extra/test/clang-tidy/modernize-make-shared-header.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<int> P1 = std::shared_ptr<int>(new int()); | ||
| // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeShared instead | ||
| // CHECK-FIXES: std::shared_ptr<int> P1 = my::MakeShared<int>(); | ||
| } |
28 changes: 4 additions & 24 deletions
28
clang-tools-extra/test/clang-tidy/modernize-make-shared.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
clang-tools-extra/test/clang-tidy/modernize-make-unique-header.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<int> P1 = std::unique_ptr<int>(new int()); | ||
| // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeUnique instead | ||
| // CHECK-FIXES: std::unique_ptr<int> P1 = my::MakeUnique<int>(); | ||
| } |
32 changes: 4 additions & 28 deletions
32
clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters