| 1 |
// RUN: %check_clang_tidy -std=c++98 %s readability-implicit-bool-conversion %t |
| 2 |
|
| 3 |
// We need NULL macro, but some buildbots don't like including <cstddef> header |
| 4 |
// This is a portable way of getting it to work |
| 5 |
#undef NULL |
| 6 |
#define NULL 0L |
| 7 |
|
| 8 |
template<typename T> |
| 9 |
void functionTaking(T); |
| 10 |
|
| 11 |
struct Struct { |
| 12 |
int member; |
| 13 |
}; |
| 14 |
|
| 15 |
void useOldNullMacroInReplacements() { |
| 16 |
int* pointer = NULL; |
| 17 |
functionTaking<bool>(pointer); |
| 18 |
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int *' -> 'bool' [readability-implicit-bool-conversion] |
| 19 |
// CHECK-FIXES: functionTaking<bool>(pointer != 0); |
| 20 |
|
| 21 |
int Struct::* memberPointer = NULL; |
| 22 |
functionTaking<bool>(!memberPointer); |
| 23 |
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit conversion 'int Struct::*' -> 'bool' |
| 24 |
// CHECK-FIXES: functionTaking<bool>(memberPointer == 0); |
| 25 |
} |
| 26 |
|
| 27 |
void fixFalseLiteralConvertingToNullPointer() { |
| 28 |
functionTaking<int*>(false); |
| 29 |
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'bool' -> 'int *' |
| 30 |
// CHECK-FIXES: functionTaking<int*>(0); |
| 31 |
|
| 32 |
int* pointer = NULL; |
| 33 |
if (pointer == false) {} |
| 34 |
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicit conversion 'bool' -> 'int *' |
| 35 |
// CHECK-FIXES: if (pointer == 0) {} |
| 36 |
|
| 37 |
functionTaking<int Struct::*>(false); |
| 38 |
// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit conversion 'bool' -> 'int Struct::*' |
| 39 |
// CHECK-FIXES: functionTaking<int Struct::*>(0); |
| 40 |
|
| 41 |
int Struct::* memberPointer = NULL; |
| 42 |
if (memberPointer != false) {} |
| 43 |
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'bool' -> 'int Struct::*' |
| 44 |
// CHECK-FIXES: if (memberPointer != 0) {} |
| 45 |
} |