105 lines · cpp
1// RUN: %check_clang_tidy %s bugprone-bool-pointer-implicit-conversion %t2 3bool *SomeFunction();4void SomeOtherFunction(bool*);5bool F();6void G(bool);7 8 9template <typename T>10void t(T b) {11 if (b) {12 }13}14 15void 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-warning41 }42 43 if (SomeFunction()) {44 // no-warning45 }46 47 bool *c = SomeFunction();48 if (c) {49 (void)c;50 (void)*c; // no-warning51 }52 53 if (c) {54 *c = true; // no-warning55 }56 57 if (c) {58 c[0] = false; // no-warning59 }60 61 if (c) {62 SomeOtherFunction(c); // no-warning63 }64 65 if (c) {66 delete[] c; // no-warning67 }68 69 if (c) {70 *(c) = false; // no-warning71 }72 73 struct {74 bool *b;75 } d = { 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-warning84 }85 86#define CHECK(b) \87 if (b) { \88 }89 CHECK(c)90}91 92struct 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-warning102 }103 }104};105