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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// RUN: %check_clang_tidy %s bugprone-suspicious-enum-usage %t -- -config="{CheckOptions: [{key: bugprone-suspicious-enum-usage.StrictMode, value: 1}]}" --
enum A {
A = 1,
B = 2,
C = 4,
D = 8,
E = 16,
F = 32,
G = 63
};
// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask (contains mostly power-of-2 literals) but a literal is not power-of-2
// CHECK-MESSAGES: :76:7: note: used here as a bitmask
enum X {
X = 8,
Y = 16,
Z = 4,
ZZ = 3
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask (contains mostly power-of-2 literals), but this literal is not a power-of-2 [bugprone-suspicious-enum-usage]
// CHECK-MESSAGES: :70:13: note: used here as a bitmask
};
// CHECK-MESSAGES: :[[@LINE+2]]:1: warning: enum type seems like a bitmask (contains mostly power-of-2 literals) but some literals are not power-of-2
// CHECK-MESSAGES: :73:8: note: used here as a bitmask
enum PP {
P = 2,
Q = 3,
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: enum type seems like a bitmask (contains mostly power-of-2 literals), but this literal is not a power-of-2
// CHECK-MESSAGES: :65:11: note: used here as a bitmask
R = 4,
S = 8,
T = 16,
U = 31
};
enum {
H,
I,
J,
K,
L
};
enum Days {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
};
Days bestDay() {
return Friday;
}
int trigger() {
if (bestDay() | A)
return 1;
// CHECK-MESSAGES: :[[@LINE-2]]:17: warning: enum values are from different enum types
if (I | Y)
return 1;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: enum values are from different enum types
if (P + Q == R)
return 1;
else if ((S | R) == T)
return 1;
else
int k = ZZ | Z;
unsigned p = R;
PP pp = Q;
p |= pp;
enum X x = Z;
p = x | Z;
return 0;
}
int dont_trigger() {
int a = 1, b = 5;
int c = a + b;
int d = c | H, e = b * a;
a = B | C;
b = X | Z;
unsigned bitflag;
enum A aa = B;
bitflag = aa | C;
if (Tuesday != Monday + 1 ||
Friday - Thursday != 1 ||
Sunday + Wednesday == (Sunday | Wednesday))
return 1;
if (H + I + L == 42)
return 1;
return 42;
}
|