Piotr Dziwinski | 7f1b509 | 2015-10-25 15:31:25 +0000 | [diff] [blame] | 1 | // RUN: clang-tidy %s -checks=-*,readability-implicit-bool-cast -- -std=c++98 |
| 2 | |
Piotr Dziwinski | db9d130 | 2015-10-25 15:47:21 +0000 | [diff] [blame^] | 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 |
Piotr Dziwinski | 7f1b509 | 2015-10-25 15:31:25 +0000 | [diff] [blame] | 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 cast 'int *' -> bool [readability-implicit-bool-cast] |
| 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 cast 'int struct 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 cast 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 cast bool -> 'int *' |
| 35 | // CHECK-FIXES: if (pointer == 0) {} |
| 36 | |
| 37 | functionTaking<int Struct::*>(false); |
| 38 | // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit cast bool -> 'int struct 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 cast bool -> 'int struct Struct::*' |
| 44 | // CHECK-FIXES: if (memberPointer != 0) {} |
| 45 | } |