blob: 1cd5c87d3358d46ad8ba78b2581435e2974efc62 [file] [log] [blame]
Piotr Dziwinski7f1b5092015-10-25 15:31:25 +00001// RUN: clang-tidy %s -checks=-*,readability-implicit-bool-cast -- -std=c++98
2
3#include <cstddef> // for NULL
4
5template<typename T>
6void functionTaking(T);
7
8struct Struct {
9 int member;
10};
11
12void 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
24void 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}