Debian Codegraph @

tests/function-args-by-ref/main.cpp.fixed.expected

raw
1 #include <QtCore/QDebug>
2 #include <QtGui/QColor>
3
4
5
6 struct Trivial {
7 int a;
8 };
9
10 struct NonTrivial {
11 NonTrivial() {}
12 NonTrivial(const NonTrivial &) {}
13 void constFunction() const {};
14 void nonConstFunction() {};
15 int a;
16 };
17
18 extern void by_pointer(NonTrivial*);
19 extern void by_const_pointer(const NonTrivial*);
20 extern void by_ref(NonTrivial&);
21 extern void by_constRef(const NonTrivial&);
22
23 int foo1(const Trivial nt) // Test #1: No warning
24 {
25 return nt.a;
26 }
27
28 int foo2(const NonTrivial &nt) // Test #2: Warning
29 {
30 nt.constFunction();
31 return nt.a;
32 }
33
34 int foo3(const NonTrivial &nt) // Test #3: Warning
35 {
36 return nt.a;
37 }
38
39 int foo4(const NonTrivial &nt) // Test #4: Warning
40 {
41 return nt.a;
42 }
43
44 int foo5(NonTrivial nt) // Test #5: No warning
45 {
46 by_pointer(&nt);
47 return nt.a;
48 }
49
50
51 int foo6(NonTrivial nt) // Test #6: No warning
52 {
53 by_ref(nt);
54 return nt.a;
55 }
56
57 int foo7(NonTrivial nt) // Test #7: No warning
58 {
59 nt.nonConstFunction();
60 return nt.a;
61 }
62
63 int foo8(const NonTrivial &nt) // Test #8: Warning
64 {
65 nt.constFunction();
66 return nt.a;
67 }
68
69 int foo9(const NonTrivial &nt) // Test #9: Warning
70 {
71 by_constRef(nt);
72 return nt.a;
73 }
74
75 int foo10(const NonTrivial &nt) // Test #10: Warning
76 {
77 by_const_pointer(&nt);
78 return nt.a;
79 }
80
81 int foo11(QColor) // Test #11: No warning
82 {
83 return 1;
84 }
85
86 int foo12(NonTrivial nt) // Test #12: No warning
87 {
88 nt = NonTrivial();
89 return 1;
90 }
91
92 void func(QString text)
93 {
94 QTextStream a(&text); // OK, by-pointer to a CTOR
95 }
96
97 struct StringConstPtr
98 {
99 StringConstPtr(const QString *s) {}
100 };
101
102 void func2(const QString &text)
103 {
104 StringConstPtr s(&text); // Warning, it's a const ptr
105 }
106
107 enum Option {
108 FooOption,
109 FooOption2
110 };
111
112
113 Q_DECLARE_FLAGS(Options, Option)
114 Q_DECLARE_OPERATORS_FOR_FLAGS(Options)
115
116 struct NoUserCtorsButNotTrivial
117 {
118 NonTrivial t;
119 };
120
121 void testNoUserCtorsButNotTrivial(const NoUserCtorsButNotTrivial&)
122 {
123
124 }
125
126 struct TrivialWithDefaultCopyCtorAndDtor
127 {
128 TrivialWithDefaultCopyCtorAndDtor(const TrivialWithDefaultCopyCtorAndDtor &) = default;
129 ~TrivialWithDefaultCopyCtorAndDtor() = default;
130 int m;
131 };
132
133 void testTrivialWithDefaultCopyCtorAndDtor(TrivialWithDefaultCopyCtorAndDtor)
134 {
135
136 }
137
138 struct DefaultButNotTrivialCopyable
139 {
140 DefaultButNotTrivialCopyable(const DefaultButNotTrivialCopyable & ) = default;
141 ~DefaultButNotTrivialCopyable() = default;
142 NonTrivial t;
143 };
144
145 void testDefaultButNotTrivialCopyable(const DefaultButNotTrivialCopyable&)
146 {
147
148 }
149
150 void shouldBeByValue(const Trivial &nt)
151 {
152
153 }
154
155
156 void isOK(const NonTrivial &&)
157 {
158 }
159
160 void foo(const Trivial &t = Trivial());
161 void foo1(const Trivial & = Trivial());
162 void foo2(const Trivial &t);
163 void foo3(const Trivial&);
164
165 void foo4(const Trivial &t);
166 void foo4(const Trivial &t)
167 {
168 }
169
170 void foo5(const Trivial &t)
171 {
172 }
173
174 void foo6(const Trivial &t = {})
175 {
176 }
177
178
179 struct Base // Test that fixits fix both Base and Derived
180 {
181 void foo(const Trivial &);
182 };
183
184 void Base::foo(const Trivial &)
185 {
186 }
187
188 struct Derived : public Base
189 {
190 void foo(const Trivial &);
191 };
192
193 void Derived::foo(const Trivial &)
194 {
195 }
196
197
198
199
200
201
202 struct DeletedCtor // bug #360112
203 {
204 Q_DISABLE_COPY(DeletedCtor)
205 };
206
207 struct CopyCtor // bug #360112
208 {
209 CopyCtor(const CopyCtor &) {}
210 };
211
212 struct Ctors
213 {
214 Ctors (const NonTrivial&) {}
215 };
216
217
218 struct Ctors2
219 {
220 Ctors2(NonTrivial n) : m(std::move(n)), i(0) {} // Ok
221 NonTrivial m;
222 int i;
223 };
224
225 struct Ctors3
226 {
227 Ctors3(const NonTrivial &n) : m(n), i(0) {} // Warning
228 NonTrivial m;
229 int i;
230 };
231
232
233 // #381812
234 class BaseWithVirtuals
235 {
236 public:
237 virtual void virtualMethod1(const NonTrivial&) {}; // Warn
238 virtual void virtualMethod2(const NonTrivial&) {}; // Warn
239 void nonVirtualMethod(const NonTrivial&) {}; // Warn
240 };
241
242 class DerivedWithVirtuals : BaseWithVirtuals {
243 public:
244 void virtualMethod1(const NonTrivial&) override {}; // OK
245 void virtualMethod2(const NonTrivial&) {}; // OK
246 void nonVirtualMethod(const NonTrivial&) {}; // Warn
247 };