summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/redundant-smartptr-get-fix.cpp
blob: 34b8cb84f9107e1b5bf2006872489358c8da1b06 (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
64
65
66
// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-redundant-smartptr-get %t
// REQUIRES: shell

namespace std {

template <typename T>
class unique_ptr {
  T& operator*() const;
  T* operator->() const;
  T* get() const;
};

template <typename T>
class shared_ptr {
  T& operator*() const;
  T* operator->() const;
  T* get() const;
};

}  // namespace std

struct Bar {
  void Do();
  void ConstDo() const;
};
struct BarPtr {
  Bar* operator->();
  Bar& operator*();
  Bar* get();
};
struct int_ptr {
  int* get();
  int* operator->();
  int& operator*();
};

void Positive() {
  BarPtr u;
  // CHECK: BarPtr u;
  BarPtr().get()->Do();
  // CHECK: BarPtr()->Do();

  u.get()->ConstDo();
  // CHECK: u->ConstDo();

  Bar& b = *BarPtr().get();
  // CHECK: Bar& b = *BarPtr();

  (*BarPtr().get()).ConstDo();
  // CHECK: (*BarPtr()).ConstDo();

  BarPtr* up;
  (*up->get()).Do();
  // CHECK: (**up).Do();

  int_ptr ip;
  int i = *ip.get();
  // CHECK: int i = *ip;

  std::unique_ptr<int> uu;
  std::shared_ptr<double> *ss;
  bool bb = uu.get() == nullptr;
  // CHECK: bool bb = uu == nullptr;
  bb = nullptr != ss->get();
  // CHECK: bb = nullptr != *ss;
}
OpenPOWER on IntegriCloud