Debian Codegraph @

build/clang-plugin/tests/TestOverrideBaseCall.cpp

raw
1 #define MOZ_REQUIRED_BASE_METHOD __attribute__((annotate("moz_required_base_method")))
2
3 class Base {
4 public:
5 virtual void fo() MOZ_REQUIRED_BASE_METHOD {
6 }
7
8 virtual int foRet() MOZ_REQUIRED_BASE_METHOD {
9 return 0;
10 }
11 };
12
13 class BaseOne : public Base {
14 public:
15 virtual void fo() MOZ_REQUIRED_BASE_METHOD {
16 Base::fo();
17 }
18 };
19
20 class BaseSecond : public Base {
21 public:
22 virtual void fo() MOZ_REQUIRED_BASE_METHOD {
23 Base::fo();
24 }
25 };
26
27 class Deriv : public BaseOne, public BaseSecond {
28 public:
29 void func() {
30 }
31
32 void fo() {
33 func();
34 BaseSecond::fo();
35 BaseOne::fo();
36 }
37 };
38
39 class DerivSimple : public Base {
40 public:
41 void fo() { // expected-error {{Method Base::fo must be called in all overrides, but is not called in this override defined for class DerivSimple}}
42 }
43 };
44
45 class BaseVirtualOne : public virtual Base {
46 };
47
48 class BaseVirtualSecond: public virtual Base {
49 };
50
51 class DerivVirtual : public BaseVirtualOne, public BaseVirtualSecond {
52 public:
53 void fo() {
54 Base::fo();
55 }
56 };
57
58 class DerivIf : public Base {
59 public:
60 void fo() {
61 if (true) {
62 Base::fo();
63 }
64 }
65 };
66
67 class DerivIfElse : public Base {
68 public:
69 void fo() {
70 if (true) {
71 Base::fo();
72 } else {
73 Base::fo();
74 }
75 }
76 };
77
78 class DerivFor : public Base {
79 public:
80 void fo() {
81 for (int i = 0; i < 10; i++) {
82 Base::fo();
83 }
84 }
85 };
86
87 class DerivDoWhile : public Base {
88 public:
89 void fo() {
90 do {
91 Base::fo();
92 } while(false);
93 }
94 };
95
96 class DerivWhile : public Base {
97 public:
98 void fo() {
99 while (true) {
100 Base::fo();
101 break;
102 }
103 }
104 };
105
106 class DerivAssignment : public Base {
107 public:
108 int foRet() {
109 return foRet();
110 }
111 };
112
113 class BaseOperator {
114 private:
115 int value;
116 public:
117 BaseOperator() : value(0) {
118 }
119 virtual BaseOperator& operator++() MOZ_REQUIRED_BASE_METHOD {
120 value++;
121 return *this;
122 }
123 };
124
125 class DerivOperatorErr : public BaseOperator {
126 private:
127 int value;
128 public:
129 DerivOperatorErr() : value(0) {
130 }
131 DerivOperatorErr& operator++() { // expected-error {{Method BaseOperator::operator++ must be called in all overrides, but is not called in this override defined for class DerivOperatorErr}}
132 value++;
133 return *this;
134 }
135 };
136
137 class DerivOperator : public BaseOperator {
138 private:
139 int value;
140 public:
141 DerivOperator() : value(0) {
142 }
143 DerivOperator& operator++() {
144 BaseOperator::operator++();
145 value++;
146 return *this;
147 }
148 };
149
150 class DerivPrime : public Base {
151 public:
152 void fo() {
153 Base::fo();
154 }
155 };
156
157 class DerivSecondErr : public DerivPrime {
158 public:
159 void fo() { // expected-error {{Method Base::fo must be called in all overrides, but is not called in this override defined for class DerivSecondErr}}
160 }
161 };
162
163 class DerivSecond : public DerivPrime {
164 public:
165 void fo() {
166 Base::fo();
167 }
168 };
169
170 class DerivSecondIndirect : public DerivPrime {
171 public:
172 void fo() {
173 DerivPrime::fo();
174 }
175 };