-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathtest.cpp
More file actions
152 lines (122 loc) · 5.48 KB
/
test.cpp
File metadata and controls
152 lines (122 loc) · 5.48 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <cstdint>
/* ========== 1. Global scope fixtures ========== */
static int32_t G1 = 1;
static int32_t G2 = 2;
/* ========== 2. Global scope enums ========== */
enum E_Global1 : int32_t { V1, V2, V3 }; // NON_COMPLIANT: unscoped at global scope
enum { GlobalAnon1, GlobalAnon2 }; // NON_COMPLIANT: unscoped anonymous at global scope
enum class E_Global2 : int32_t { V1, V2 }; // COMPLIANT: scoped enum
/* ========== 3. Nested namespaces ========== */
namespace N1 {
static int32_t N1_V1 = 1;
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in namespace + hides ::G1
enum { N1_Anon1, N1_Anon2 }; // NON_COMPLIANT: unscoped anonymous in namespace
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
namespace N2 {
static int32_t N2_V1 = 1;
enum E3 : int32_t { N1_V1 }; // NON_COMPLIANT: unscoped in namespace + hides N1::N1_V1
enum E4 : int32_t { G2 }; // NON_COMPLIANT: unscoped in namespace + hides ::G2
enum class E5 : int32_t { N1_V1, G2 }; // COMPLIANT: scoped enum
}
}
/* ========== 4. Anonymous namespace ========== */
namespace {
enum E_Anon1 : int32_t { V1, V2 }; // NON_COMPLIANT: unscoped in anonymous namespace
enum { AnonAnon1, AnonAnon2 }; // NON_COMPLIANT: unscoped anonymous in anonymous namespace
enum class E_Anon2 : int32_t { V1 }; // COMPLIANT: scoped enum
}
/* ========== 5. Anonymous namespace inside named namespace ========== */
namespace N3 {
static int32_t N3_V1 = 1;
namespace {
enum E1 : int32_t { N3_V1 }; // NON_COMPLIANT: unscoped + hides N3::N3_V1
enum class E2 : int32_t { N3_V1 }; // COMPLIANT: scoped enum
}
}
/* ========== 6. Nested classes ========== */
class C1 {
static int32_t C1_V1;
enum E1 { G1 }; // COMPLIANT: unscoped in class (exception) + hides ::G1
enum { C1_Anon1, C1_Anon2 }; // COMPLIANT: unscoped anonymous in class (exception)
enum class E2 { G1 }; // COMPLIANT: scoped enum
class C2 {
enum E3 { C1_V1 }; // COMPLIANT: unscoped in nested class (exception)
enum E4 { G2 }; // COMPLIANT: unscoped in nested class (exception) + hides ::G2
struct S1 {
enum E5 { C1_V1 }; // COMPLIANT: unscoped in struct (exception)
enum class E6 { C1_V1 }; // COMPLIANT: scoped enum
};
};
};
/* ========== 7. Struct at global scope ========== */
struct S_Global {
enum E1 { G1 }; // COMPLIANT: unscoped in struct (exception)
enum { S_Anon1, S_Anon2 }; // COMPLIANT: unscoped anonymous in struct (exception)
enum class E2 { G1 }; // COMPLIANT: scoped enum
};
/* ========== 8. Class inside namespace ========== */
namespace N4 {
static int32_t N4_V1 = 1;
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in namespace
class C1 {
enum E2 { N4_V1 }; // COMPLIANT: unscoped in class (exception) + hides N4::N4_V1
enum E3 { G2 }; // COMPLIANT: unscoped in class (exception) + hides ::G2
enum class E4 { N4_V1, G2 }; // COMPLIANT: scoped enum
};
}
/* ========== 9. Function body ========== */
void f1() {
int F1_V1 = 1;
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in function + hides ::G1
enum { F1_Anon1, F1_Anon2 }; // NON_COMPLIANT: unscoped anonymous in function
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
}
/* ========== 10. Nested blocks ========== */
void f2() {
int F2_V1 = 1;
{
int F2_V2 = 2;
enum E1 : int32_t { F2_V1 }; // NON_COMPLIANT: unscoped in block + hides outer F2_V1
enum E2 : int32_t { G2 }; // NON_COMPLIANT: unscoped in block + hides ::G2
{
enum E3 : int32_t { F2_V2 }; // NON_COMPLIANT: unscoped in nested block + hides outer F2_V2
enum class E4 : int32_t { F2_V1, F2_V2, G1 }; // COMPLIANT: scoped enum
}
}
}
/* ========== 11. Local class in function ========== */
void f3() {
int F3_V1 = 1;
class LocalC1 {
enum E1 { F3_V1 }; // COMPLIANT: unscoped in local class (exception)
enum E2 { G1 }; // COMPLIANT: unscoped in local class (exception) + hides ::G1
enum { Local_Anon1 }; // COMPLIANT: unscoped anonymous in local class (exception)
enum class E3 { F3_V1, G1 }; // COMPLIANT: scoped enum
};
}
/* ========== 12. Lambda body ========== */
auto lambda1 = []() {
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in lambda body
enum { Lambda_Anon1 }; // NON_COMPLIANT: unscoped anonymous in lambda body
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
};
/* ========== 13. Nested lambdas ========== */
namespace N5 {
auto lambda2 = []() {
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in lambda body
auto nested_lambda = []() {
enum E2 : int32_t { G2 }; // NON_COMPLIANT: unscoped in nested lambda body
enum class E3 : int32_t { G1, G2 }; // COMPLIANT: scoped enum
};
};
}
/* ========== 14. Lambda inside class ========== */
class C3 {
static inline auto member_lambda = []() {
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in lambda body (not class scope!)
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
};
};
int main() {
return 0;
}