summaryrefslogtreecommitdiffstats
path: root/tools/clang-tidy/test/readability-implicit-bool-conversion.cpp
blob: c30089a12604f2bdc13bd1ad351ed7bc669c475f (plain)
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
46
47
48
49
50
51
52
53
54
55
#define MOZ_IMPLICIT __attribute__((annotate("moz_implicit")))

void takesChar(char);
void takesShort(short);
void takesInt(int);
void takesLong(long);

void takesUChar(unsigned char);
void takesUShort(unsigned short);
void takesUInt(unsigned int);
void takesULong(unsigned long);

struct InitializedWithInt {
  MOZ_IMPLICIT InitializedWithInt(int);
};

void f() {
  bool b = true;
  char s0 = b;
  short s1 = b;
  int s2 = b;
  long s3 = b;

  unsigned char u0 = b;
  unsigned short u1 = b;
  unsigned u2 = b;
  unsigned long u3 = b;

  takesChar(b);
  takesShort(b);
  takesInt(b);
  takesLong(b);
  takesUChar(b);
  takesUShort(b);
  takesUInt(b);
  takesULong(b);

  InitializedWithInt i = b;
  (InitializedWithInt(b));

  bool x = b;

  int exp = (int)true;

  if (x == b) {}
  if (x != b) {}

  if (b == exp) {}
  if (exp == b) {}

  char* ptr;
  // Shouldn't trigger a checker warning since we are using AllowPointerConditions
  if (ptr) {}
}