summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/cpp11-migrate/ReplaceAutoPtr/move.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/test/cpp11-migrate/ReplaceAutoPtr/move.cpp')
-rw-r--r--clang-tools-extra/test/cpp11-migrate/ReplaceAutoPtr/move.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/clang-tools-extra/test/cpp11-migrate/ReplaceAutoPtr/move.cpp b/clang-tools-extra/test/cpp11-migrate/ReplaceAutoPtr/move.cpp
new file mode 100644
index 00000000000..d0e9ce14098
--- /dev/null
+++ b/clang-tools-extra/test/cpp11-migrate/ReplaceAutoPtr/move.cpp
@@ -0,0 +1,63 @@
+// Without inline namespace:
+//
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -replace-auto_ptr %t.cpp -- -I %S/Inputs std=c++11
+// RUN: FileCheck -input-file=%t.cpp %s
+//
+// With inline namespace:
+//
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: cpp11-migrate -replace-auto_ptr %t.cpp -- -I %S/Inputs std=c++11 \
+// RUN: -DUSE_INLINE_NAMESPACE=1
+// RUN: FileCheck -input-file=%t.cpp %s
+
+#include "memory_stub.h"
+
+void takes_ownership_fn(std::auto_ptr<int> x);
+// CHECK: void takes_ownership_fn(std::unique_ptr<int> x);
+
+std::auto_ptr<int> get_by_value();
+// CHECK: std::unique_ptr<int> get_by_value();
+
+class Wrapper {
+public:
+ std::auto_ptr<int> &get_wrapped();
+
+private:
+ std::auto_ptr<int> wrapped;
+};
+
+void f() {
+ std::auto_ptr<int> a, b, c;
+ // CHECK: std::unique_ptr<int> a, b, c;
+ Wrapper wrapper_a, wrapper_b;
+
+ a = b;
+ // CHECK: a = std::move(b);
+
+ wrapper_a.get_wrapped() = wrapper_b.get_wrapped();
+ // CHECK: wrapper_a.get_wrapped() = std::move(wrapper_b.get_wrapped());
+
+ // Test that 'std::move()' is inserted when call to the
+ // copy-constructor are made.
+ takes_ownership_fn(c);
+ // CHECK: takes_ownership_fn(std::move(c));
+ takes_ownership_fn(wrapper_a.get_wrapped());
+ // CHECK: takes_ownership_fn(std::move(wrapper_a.get_wrapped()));
+
+ std::auto_ptr<int> d[] = { std::auto_ptr<int>(new int(1)),
+ std::auto_ptr<int>(new int(2)) };
+ std::auto_ptr<int> e = d[0];
+ // CHECK: std::unique_ptr<int> d[] = { std::unique_ptr<int>(new int(1)),
+ // CHECK-NEXT: std::unique_ptr<int>(new int(2)) };
+ // CHECK-NEXT: std::unique_ptr<int> e = std::move(d[0]);
+
+ // Test that std::move() is not used when assigning an rvalue
+ std::auto_ptr<int> f;
+ f = std::auto_ptr<int>(new int(0));
+ // CHECK: std::unique_ptr<int> f;
+ // CHECK-NEXT: f = std::unique_ptr<int>(new int(0));
+
+ std::auto_ptr<int> g = get_by_value();
+ // CHECK: std::unique_ptr<int> g = get_by_value();
+}
OpenPOWER on IntegriCloud