summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/cpp11-migrate/ReplaceAutoPtr/move.cpp
blob: d0e9ce14098932023a89de504d2fbac1f93862a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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