Debian Codegraph @

tests/unused-result-check/main.cpp

raw
1 #include <QtCore/QObject>
2
3 class A : public QObject
4 {
5 Q_OBJECT
6 public:
7 int g;
8 A()
9 : g(foo()) // OK
10 {
11 }
12 bool foo_bool() const
13 {
14 return true;
15 }
16 int foo() const
17 {
18 return 5;
19 }
20 void bar() const
21 {
22 foo(); // WARN
23 if (foo()) // OK
24 { }
25 }
26 };
27
28 class B
29 {
30 public:
31 A a;
32 B()
33 : g(a.foo()) // OK
34 {
35 }
36 int g;
37 };
38
39 class C
40 {
41 public:
42 A a;
43 };
44
45 int main(int argc, char *argv[])
46 {
47 A a;
48 B b;
49 a.bar();
50 auto lambda = [](A &obj) {
51 obj.foo(); // WARN
52 };
53 lambda(a);
54
55 C *c = new C();
56 if (c->a.foo_bool()) { // OK
57 }
58 while (c->a.foo_bool()) { // OK
59 A obj;
60 obj.foo(); // WARN
61
62 int x = 10;
63 switch (c->a.foo()) { // OK
64 case 1:
65 A bar;
66 bar.foo(); // WARN
67 break;
68 }
69
70 for (int i = 0; i < (c->a.foo()); i++) {
71 A bar;
72 bar.foo(); // WARN
73 }
74
75 do {
76 A bar;
77 bar.foo(); // WARN
78 } while (c->a.foo_bool()); // OK
79 }
80 return 0;
81 }