1 | // RUN: %check_clang_tidy %s bugprone-bool-pointer-implicit-conversion %t |
2 | |
3 | bool *SomeFunction(); |
4 | void SomeOtherFunction(bool*); |
5 | bool F(); |
6 | void G(bool); |
7 | |
8 | |
9 | template <typename T> |
10 | void t(T b) { |
11 | if (b) { |
12 | } |
13 | } |
14 | |
15 | void foo() { |
16 | bool *b = SomeFunction(); |
17 | if (b) { |
18 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: dubious check of 'bool *' against 'nullptr' |
19 | // CHECK-FIXES: if (*b) { |
20 | } |
21 | |
22 | if (F() && b) { |
23 | // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: dubious check of 'bool *' against 'nullptr' |
24 | // CHECK-FIXES: if (F() && *b) { |
25 | } |
26 | |
27 | // TODO: warn here. |
28 | if (b) { |
29 | G(b); |
30 | } |
31 | |
32 | #define TESTMACRO if (b || F()) |
33 | |
34 | TESTMACRO { |
35 | } |
36 | |
37 | t(b); |
38 | |
39 | if (!b) { |
40 | // no-warning |
41 | } |
42 | |
43 | if (SomeFunction()) { |
44 | // no-warning |
45 | } |
46 | |
47 | bool *c = SomeFunction(); |
48 | if (c) { |
49 | (void)c; |
50 | (void)*c; // no-warning |
51 | } |
52 | |
53 | if (c) { |
54 | *c = true; // no-warning |
55 | } |
56 | |
57 | if (c) { |
58 | c[0] = false; // no-warning |
59 | } |
60 | |
61 | if (c) { |
62 | SomeOtherFunction(c); // no-warning |
63 | } |
64 | |
65 | if (c) { |
66 | delete[] c; // no-warning |
67 | } |
68 | |
69 | if (c) { |
70 | *(c) = false; // no-warning |
71 | } |
72 | |
73 | struct { |
74 | bool *b; |
75 | } d = { .b: SomeFunction() }; |
76 | |
77 | if (d.b) { |
78 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: dubious check of 'bool *' against 'nullptr' |
79 | // CHECK-FIXES: if (*d.b) { |
80 | } |
81 | |
82 | if (d.b) { |
83 | (void)*d.b; // no-warning |
84 | } |
85 | |
86 | #define CHECK(b) \ |
87 | if (b) { \ |
88 | } |
89 | CHECK(c) |
90 | } |
91 | |
92 | struct H { |
93 | bool *b; |
94 | void foo() const { |
95 | if (b) { |
96 | // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: dubious check of 'bool *' against 'nullptr' |
97 | // CHECK-FIXES: if (*b) { |
98 | } |
99 | |
100 | if (b) { |
101 | (void)*b; // no-warning |
102 | } |
103 | } |
104 | }; |
105 | |