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 | |
| 3 | #include <cstddef> // for NULL |
| 4 | |
| 5 | template<typename T> |
| 6 | void functionTaking(T); |
| 7 | |
| 8 | struct Struct { |
| 9 | int member; |
| 10 | }; |
| 11 | |
| 12 | void useOldNullMacroInReplacements() { |
| 13 | int* pointer = NULL; |
| 14 | functionTaking<bool>(pointer); |
| 15 | // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit cast 'int *' -> bool [readability-implicit-bool-cast] |
| 16 | // CHECK-FIXES: functionTaking<bool>(pointer != 0); |
| 17 | |
| 18 | int Struct::* memberPointer = NULL; |
| 19 | functionTaking<bool>(!memberPointer); |
| 20 | // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit cast 'int struct Struct::*' -> bool |
| 21 | // CHECK-FIXES: functionTaking<bool>(memberPointer == 0); |
| 22 | } |
| 23 | |
| 24 | void fixFalseLiteralConvertingToNullPointer() { |
| 25 | functionTaking<int*>(false); |
| 26 | // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit cast bool -> 'int *' |
| 27 | // CHECK-FIXES: functionTaking<int*>(0); |
| 28 | |
| 29 | int* pointer = NULL; |
| 30 | if (pointer == false) {} |
| 31 | // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicit cast bool -> 'int *' |
| 32 | // CHECK-FIXES: if (pointer == 0) {} |
| 33 | |
| 34 | functionTaking<int Struct::*>(false); |
| 35 | // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit cast bool -> 'int struct Struct::*' |
| 36 | // CHECK-FIXES: functionTaking<int Struct::*>(0); |
| 37 | |
| 38 | int Struct::* memberPointer = NULL; |
| 39 | if (memberPointer != false) {} |
| 40 | // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit cast bool -> 'int struct Struct::*' |
| 41 | // CHECK-FIXES: if (memberPointer != 0) {} |
| 42 | } |