diff options
author | Samuel Benzaquen <sbenza@google.com> | 2015-04-09 17:51:01 +0000 |
---|---|---|
committer | Samuel Benzaquen <sbenza@google.com> | 2015-04-09 17:51:01 +0000 |
commit | 91d85dc6bc2fa2837b74fe05443824df7cdde6bd (patch) | |
tree | 44c0edecb2595fba0bdc217e7a4761a11cc9618c /clang-tools-extra/test | |
parent | 6d61b63cc50b26949aa0f78c6d90a0044bc1d432 (diff) | |
download | bcm5719-llvm-91d85dc6bc2fa2837b74fe05443824df7cdde6bd.tar.gz bcm5719-llvm-91d85dc6bc2fa2837b74fe05443824df7cdde6bd.zip |
[clang-tidy] Ignore expressions with incompatible deleters.
Summary:
Do not warn on .reset(.release()) expressions if the deleters are not
compatible.
Using plain assignment will probably not work.
Reviewers: klimek
Subscribers: curdeius, cfe-commits
Differential Revision: http://reviews.llvm.org/D8422
llvm-svn: 234512
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp b/clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp index 2839f167b9f..3d1183991f2 100644 --- a/clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp +++ b/clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp @@ -2,12 +2,16 @@ // REQUIRES: shell namespace std { + template <typename T> +struct default_delete {}; + +template <typename T, class Deleter = std::default_delete<T>> struct unique_ptr { - unique_ptr<T>(); - explicit unique_ptr<T>(T *); - template <typename U> - unique_ptr<T>(unique_ptr<U> &&); + unique_ptr(); + explicit unique_ptr(T *); + template <typename U, typename E> + unique_ptr(unique_ptr<U, E> &&); void reset(T *); T *release(); }; @@ -20,6 +24,9 @@ std::unique_ptr<Foo> Create(); std::unique_ptr<Foo> &Look(); std::unique_ptr<Foo> *Get(); +using FooFunc = void (*)(Foo *); +using BarFunc = void (*)(Bar *); + void f() { std::unique_ptr<Foo> a, b; std::unique_ptr<Bar> c; @@ -44,5 +51,20 @@ void f() { Get()->reset(Get()->release()); // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr1 = std::move(ptr2) // CHECK-FIXES: *Get() = std::move(*Get()); + + std::unique_ptr<Bar, FooFunc> func_a, func_b; + func_a.reset(func_b.release()); + // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr1 = std::move(ptr2) + // CHECK-FIXES: func_a = std::move(func_b); } +void negatives() { + std::unique_ptr<Foo> src; + struct OtherDeleter {}; + std::unique_ptr<Foo, OtherDeleter> dest; + dest.reset(src.release()); + + std::unique_ptr<Bar, FooFunc> func_a; + std::unique_ptr<Bar, BarFunc> func_b; + func_a.reset(func_b.release()); +} |