File: readability-implicit-bool-conversion-cxx98.cpp

package info (click to toggle)
llvm-toolchain-6.0 1%3A6.0.1-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 598,080 kB
  • sloc: cpp: 3,046,253; ansic: 595,057; asm: 271,965; python: 128,926; objc: 106,554; sh: 21,906; lisp: 10,191; pascal: 6,094; ml: 5,544; perl: 5,265; makefile: 2,227; cs: 2,027; xml: 686; php: 212; csh: 117
file content (45 lines) | stat: -rw-r--r-- 1,600 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// RUN: %check_clang_tidy %s readability-implicit-bool-conversion %t -- -- -std=c++98

// We need NULL macro, but some buildbots don't like including <cstddef> header
// This is a portable way of getting it to work
#undef NULL
#define NULL 0L

template<typename T>
void functionTaking(T);

struct Struct {
  int member;
};

void useOldNullMacroInReplacements() {
  int* pointer = NULL;
  functionTaking<bool>(pointer);
  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'int *' -> bool [readability-implicit-bool-conversion]
  // CHECK-FIXES: functionTaking<bool>(pointer != 0);

  int Struct::* memberPointer = NULL;
  functionTaking<bool>(!memberPointer);
  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit conversion 'int Struct::*' -> bool
  // CHECK-FIXES: functionTaking<bool>(memberPointer == 0);
}

void fixFalseLiteralConvertingToNullPointer() {
  functionTaking<int*>(false);
  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion bool -> 'int *'
  // CHECK-FIXES: functionTaking<int*>(0);

  int* pointer = NULL;
  if (pointer == false) {}
  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicit conversion bool -> 'int *'
  // CHECK-FIXES: if (pointer == 0) {}

  functionTaking<int Struct::*>(false);
  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: implicit conversion bool -> 'int Struct::*'
  // CHECK-FIXES: functionTaking<int Struct::*>(0);

  int Struct::* memberPointer = NULL;
  if (memberPointer != false) {}
  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion bool -> 'int Struct::*'
  // CHECK-FIXES: if (memberPointer != 0) {}
}