diff options
Diffstat (limited to 'clang-tools-extra/test/clang-tidy')
6 files changed, 94 insertions, 52 deletions
diff --git a/clang-tools-extra/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h b/clang-tools-extra/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h new file mode 100644 index 00000000000..0f4f2a97095 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h @@ -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 diff --git a/clang-tools-extra/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h b/clang-tools-extra/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h new file mode 100644 index 00000000000..4fc3da106f6 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h @@ -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 diff --git a/clang-tools-extra/test/clang-tidy/modernize-make-shared-header.cpp b/clang-tools-extra/test/clang-tidy/modernize-make-shared-header.cpp new file mode 100644 index 00000000000..21b07ee4496 --- /dev/null +++ b/clang-tools-extra/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<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>(); +} diff --git a/clang-tools-extra/test/clang-tidy/modernize-make-shared.cpp b/clang-tools-extra/test/clang-tidy/modernize-make-shared.cpp index 4f478419dc4..ed4da998ec5 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-make-shared.cpp +++ b/clang-tools-extra/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 <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; -}; -} +#include "shared_ptr.h" +// CHECK-FIXES: #include <memory> struct Base { Base(); diff --git a/clang-tools-extra/test/clang-tidy/modernize-make-unique-header.cpp b/clang-tools-extra/test/clang-tidy/modernize-make-unique-header.cpp new file mode 100644 index 00000000000..e6c2a613d9f --- /dev/null +++ b/clang-tools-extra/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<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>(); +} diff --git a/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp b/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp index 4dfaed2105d..551f38d7dfd 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp +++ b/clang-tools-extra/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 <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; -}; -} +#include "unique_ptr.h" +// CHECK-FIXES: #include <memory> struct Base { Base(); |