summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/cpp11-migrate/AddOverride/basic.cpp
blob: 4bc471015dff499323067be94333826e9a952099 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
// RUN: cpp11-migrate -add-override %t.cpp -- -I %S -std=c++11
// RUN: FileCheck -input-file=%t.cpp %s

class A {
public:
  virtual ~A();
  // CHECK: virtual ~A();
  void f();
  virtual void h() const;
  // CHECK: virtual void h() const;
  virtual void i() = 0;
  // CHECK: virtual void i() = 0;
};

// Test that override isn't added to non-virtual functions.
class B : public A {
public:
  void f();
  // CHECK: class B
  // CHECK: void f();
};

// Test that override is added to functions that override virtual functions.
class C : public A {
public:
  void h() const;
  // CHECK: class C
  // CHECK: void h() const override;
};

// Test that override isn't add to functions that overload but not override.
class D : public A {
public:
  void h();
  // CHECK: class D
  // CHECK: void h();
};

// Test that override isn't added again to functions that already have it.
class E : public A {
public:
  void h() const override;
  // CHECK: class E
  // CHECK: void h() const override;
};

// Test that override isn't added to the destructor.
class F : public A {
public:
  virtual ~F();
  // CHECK: class F
  // CHECK: virtual ~F();
};

// Test that override is placed before any end of line comments.
class G : public A {
public:
  void h() const; // comment
  void i() // comment
  {}
  // CHECK: class G
  // CHECK: void h() const override; // comment
  // CHECK: void i() override // comment
  // CHECK-NEXT: {}
};

// Test that override is placed correctly if there is an inline body.
class H : public A {
public:
  void h() const { }
  // CHECK: class H
  // CHECK: void h() const override { }
};

// Test that override is placed correctly if there is a body on the next line.
class I : public A {
public:
  void h() const
  { }
  // CHECK: class I
  // CHECK: void h() const override
  // CHECK: { }
};

// Test that override is placed correctly if there is a body outside the class.
class J : public A {
public:
  void h() const;
  // CHECK: class J
  // CHECK: void h() const override;
};

void J::h() const {
  // CHECK: void J::h() const {
}

// Test that override is placed correctly if there is a trailing return type.
class K : public A {
public:
  auto h() const -> void;
  // CHECK: class K
  // CHECK: auto h() const -> void override;
};

// Test that override isn't added if it is already specified via a macro.
class L : public A {
public:
#define LLVM_OVERRIDE override
  void h() const LLVM_OVERRIDE;
  // CHECK: class L
  // CHECK: void h() const LLVM_OVERRIDE;
};

// Test that override isn't added at the wrong place for "pure overrides"
struct APure {
  virtual APure *clone() = 0;
};
struct BPure : APure {
  virtual BPure *clone() { return new BPure(); }
};
struct CPure : BPure {
  virtual BPure *clone() = 0;
  // CHECK: struct CPure : BPure {
  // CHECK-NOT: virtual BPure *clone() = 0 override;
  // CHECK: };
};
struct DPure : CPure {
  virtual DPure *clone() { return new DPure(); }
};

// Test that override is not added on dangerous template constructs
struct Base1 {
  virtual void f();
};
struct Base2 {};
template<typename T> struct Derived : T {
  void f(); // adding 'override' here will break instantiation of Derived<Base2>
  // CHECK: struct Derived
  // CHECK: void f();
};
Derived<Base1> d1;
Derived<Base2> d2;

template <typename T>
class M : public A {
public:
  virtual void i();
  // CHECK: class M : public A {
  // CHECK: virtual void i() override;
};
M<int> b;
OpenPOWER on IntegriCloud