bugprone-suspicious-enum-usage.cpp
1.33 KB
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
// RUN: %check_clang_tidy %s bugprone-suspicious-enum-usage %t -- -config="{CheckOptions: [{key: bugprone-suspicious-enum-usage.StrictMode, value: 0}]}" --
enum Empty {
};
enum A {
A = 1,
B = 2,
C = 4,
D = 8,
E = 16,
F = 32,
G = 63
};
enum X {
X = 8,
Y = 16,
Z = 4
};
enum {
P = 2,
Q = 3,
R = 4,
S = 8,
T = 16
};
enum {
H,
I,
J,
K,
L
};
enum Days {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
};
Days bestDay() {
return Friday;
}
int trigger() {
Empty EmptyVal;
int emptytest = EmptyVal | B;
if (bestDay() | A)
return 1;
// CHECK-NOTES: :[[@LINE-2]]:17: warning: enum values are from different enum types
if (I | Y)
return 1;
// CHECK-NOTES: :[[@LINE-2]]:9: warning: enum values are from different enum types
}
int dont_trigger() {
unsigned p;
p = Q | P;
if (A + G == E)
return 1;
else if ((Q | R) == T)
return 1;
else
int k = T | Q;
Empty EmptyVal;
int emptytest = EmptyVal | B;
int a = 1, b = 5;
int c = a + b;
int d = c | H, e = b * a;
a = B | C;
b = X | Z;
if (Tuesday != Monday + 1 ||
Friday - Thursday != 1 ||
Sunday + Wednesday == (Sunday | Wednesday))
return 1;
if (H + I + L == 42)
return 1;
return 42;
}
namespace PR34400 {
enum { E1 = 0 };
enum { E2 = -1 };
enum { l = E1 | E2 };
}