Clang Project

clang_source_code/test/clang-rename/ComplicatedClassType.cpp
1// Forward declaration.
2class Foo; /* Test 1 */               // CHECK: class Bar; /* Test 1 */
3
4class Baz {
5  virtual int getValue() const = 0;
6};
7
8class Foo : public Baz  { /* Test 2 */// CHECK: class Bar : public Baz {
9public:
10  Foo(int value = 0) : x(value) {}    // CHECK: Bar(int value = 0) : x(value) {}
11
12  Foo &operator++(int) {              // CHECK: Bar &operator++(int) {
13    x++;
14    return *this;
15  }
16
17  bool operator<(Foo const &rhs) {    // CHECK: bool operator<(Bar const &rhs) {
18    return this->x < rhs.x;
19  }
20
21  int getValue() const {
22    return 0;
23  }
24
25private:
26  int x;
27};
28
29int main() {
30  Foo *Pointer = 0;                   // CHECK: Bar *Pointer = 0;
31  Foo Variable = Foo(10);             // CHECK: Bar Variable = Bar(10);
32  for (Foo it; it < Variable; it++) { // CHECK: for (Bar it; it < Variable; it++) {
33  }
34  const Foo *C = new Foo();           // CHECK: const Bar *C = new Bar();
35  const_cast<Foo *>(C)->getValue();   // CHECK: const_cast<Bar *>(C)->getValue();
36  Foo foo;                            // CHECK: Bar foo;
37  const Baz &BazReference = foo;
38  const Baz *BazPointer = &foo;
39  dynamic_cast<const Foo &>(BazReference).getValue();     /* Test 3 */ // CHECK: dynamic_cast<const Bar &>(BazReference).getValue();
40  dynamic_cast<const Foo *>(BazPointer)->getValue();      /* Test 4 */ // CHECK: dynamic_cast<const Bar *>(BazPointer)->getValue();
41  reinterpret_cast<const Foo *>(BazPointer)->getValue();  /* Test 5 */ // CHECK: reinterpret_cast<const Bar *>(BazPointer)->getValue();
42  static_cast<const Foo &>(BazReference).getValue();      /* Test 6 */ // CHECK: static_cast<const Bar &>(BazReference).getValue();
43  static_cast<const Foo *>(BazPointer)->getValue();       /* Test 7 */ // CHECK: static_cast<const Bar *>(BazPointer)->getValue();
44  return 0;
45}
46
47// Test 1.
48// RUN: clang-rename -offset=30 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
49// Test 2.
50// RUN: clang-rename -offset=155 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
51// Test 3.
52// RUN: clang-rename -offset=1133 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
53// Test 4.
54// RUN: clang-rename -offset=1266 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
55// Test 5.
56// RUN: clang-rename -offset=1402 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
57// Test 6.
58// RUN: clang-rename -offset=1533 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
59// Test 7.
60// RUN: clang-rename -offset=1665 -new-name=Bar %s -- -frtti | sed 's,//.*,,' | FileCheck %s
61
62// To find offsets after modifying the file, use:
63//   grep -Ubo 'Foo.*' <file>
64