Summary: clang_tidy/rename_check.py misc-assert-side-effect bugprone-assert-side-effect clang_tidy/rename_check.py misc-bool-pointer-implicit-conversion bugprone-bool-pointer-implicit-conversion clang_tidy/rename_check.py misc-fold-init-type bugprone-fold-init-type clang_tidy/rename_check.py misc-forward-declaration-namespace bugprone-forward-declaration-namespace clang_tidy/rename_check.py misc-inaccurate-erase bugprone-inaccurate-erase clang_tidy/rename_check.py misc-move-forwarding-reference bugprone-move-forwarding-reference clang_tidy/rename_check.py misc-multiple-statement-macro bugprone-multiple-statement-macro clang_tidy/rename_check.py misc-use-after-move bugprone-use-after-move clang_tidy/rename_check.py misc-virtual-near-miss bugprone-virtual-near-miss Manually fixed a reference to UseAfterMoveCheck in the hicpp module. Manually fixed header guards. Reviewers: hokein Reviewed By: hokein Subscribers: nemanjai, mgorny, javed.absar, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D40426 llvm-svn: 318950
83 lines
1.2 KiB
C++
83 lines
1.2 KiB
C++
// RUN: %check_clang_tidy %s bugprone-bool-pointer-implicit-conversion %t
|
|
|
|
bool *SomeFunction();
|
|
void SomeOtherFunction(bool*);
|
|
bool F();
|
|
void G(bool);
|
|
|
|
|
|
template <typename T>
|
|
void t(T b) {
|
|
if (b) {
|
|
}
|
|
}
|
|
|
|
void foo() {
|
|
bool *b = SomeFunction();
|
|
if (b) {
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: dubious check of 'bool *' against 'nullptr'
|
|
// CHECK-FIXES: if (*b) {
|
|
}
|
|
|
|
if (F() && b) {
|
|
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: dubious check of 'bool *' against 'nullptr'
|
|
// CHECK-FIXES: if (F() && *b) {
|
|
}
|
|
|
|
// TODO: warn here.
|
|
if (b) {
|
|
G(b);
|
|
}
|
|
|
|
#define TESTMACRO if (b || F())
|
|
|
|
TESTMACRO {
|
|
}
|
|
|
|
t(b);
|
|
|
|
if (!b) {
|
|
// no-warning
|
|
}
|
|
|
|
if (SomeFunction()) {
|
|
// no-warning
|
|
}
|
|
|
|
bool *c = SomeFunction();
|
|
if (c) {
|
|
(void)c;
|
|
(void)*c; // no-warning
|
|
}
|
|
|
|
if (c) {
|
|
*c = true; // no-warning
|
|
}
|
|
|
|
if (c) {
|
|
c[0] = false; // no-warning
|
|
}
|
|
|
|
if (c) {
|
|
SomeOtherFunction(c); // no-warning
|
|
}
|
|
|
|
if (c) {
|
|
delete[] c; // no-warning
|
|
}
|
|
|
|
if (c) {
|
|
*(c) = false; // no-warning
|
|
}
|
|
|
|
struct {
|
|
bool *b;
|
|
} d = { SomeFunction() };
|
|
|
|
if (d.b)
|
|
(void)*d.b; // no-warning
|
|
|
|
#define CHECK(b) if (b) {}
|
|
CHECK(c)
|
|
}
|