blob: 0d8f56aa629391dbb421b48d782fa21851b1a902 [file] [log] [blame]
Piotr Dziwinski7f1b5092015-10-25 15:31:25 +00001// RUN: clang-tidy %s -checks=-*,readability-implicit-bool-cast -- -std=c++98
2
Piotr Dziwinskidb9d1302015-10-25 15:47:21 +00003// 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 Dziwinski7f1b5092015-10-25 15:31:25 +00007
8template<typename T>
9void functionTaking(T);
10
11struct Struct {
12 int member;
13};
14
15void 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
27void 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}