summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2014-12-05 11:59:05 +0000
committerAlexander Kornienko <alexfh@google.com>2014-12-05 11:59:05 +0000
commitbc0c423a46adde261cee400a74a84311c84ce287 (patch)
tree7655d49a58e5a1e25e741b3120443458d3d2a622 /clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp
parent31f6c54733031ce9f6a05444d0ef10eec481d729 (diff)
downloadbcm5719-llvm-bc0c423a46adde261cee400a74a84311c84ce287.tar.gz
bcm5719-llvm-bc0c423a46adde261cee400a74a84311c84ce287.zip
[clang-tidy] Add clang-tidy check for unique_ptr's reset+release -> move
Replace x.reset(y.release()); with x = std::move(y); If y is rvalue, replace with x = y; instead. http://reviews.llvm.org/D6485 Patch by Alexey Sokolov! llvm-svn: 223460
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp48
1 files changed, 48 insertions, 0 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
new file mode 100644
index 00000000000..763a428ecd9
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/misc-uniqueptr-reset-release.cpp
@@ -0,0 +1,48 @@
+// RUN: $(dirname %s)/check_clang_tidy.sh %s misc-uniqueptr-reset-release %t
+// REQUIRES: shell
+
+namespace std {
+template <typename T>
+struct unique_ptr {
+ unique_ptr<T>();
+ explicit unique_ptr<T>(T *);
+ template <typename U>
+ unique_ptr<T>(unique_ptr<U> &&);
+ void reset(T *);
+ T *release();
+};
+} // namespace std
+
+struct Foo {};
+struct Bar : Foo {};
+
+std::unique_ptr<Foo> Create();
+std::unique_ptr<Foo> &Look();
+std::unique_ptr<Foo> *Get();
+
+void f() {
+ std::unique_ptr<Foo> a, b;
+ std::unique_ptr<Bar> c;
+ std::unique_ptr<Foo> *x = &a;
+ std::unique_ptr<Foo> *y = &b;
+
+ a.reset(b.release());
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr1 = std::move(ptr2) over ptr1.reset(ptr2.release()) [misc-uniqueptr-reset-release]
+ // CHECK-FIXES: a = std::move(b);
+ a.reset(c.release());
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr1 = std::move(ptr2)
+ // CHECK-FIXES: a = std::move(c);
+ a.reset(Create().release());
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: prefer ptr1 = std::move(ptr2)
+ // CHECK-FIXES: a = Create();
+ x->reset(y->release());
+ // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: prefer ptr1 = std::move(ptr2)
+ // CHECK-FIXES: *x = std::move(*y);
+ Look().reset(Look().release());
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr1 = std::move(ptr2)
+ // CHECK-FIXES: Look() = std::move(Look());
+ Get()->reset(Get()->release());
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: prefer ptr1 = std::move(ptr2)
+ // CHECK-FIXES: *Get() = std::move(*Get());
+}
+
OpenPOWER on IntegriCloud