Skip to content

Commit 2e62897

Browse files
committed
Fix formatting of test case for 10.2.2
1 parent 7f4ebd4 commit 2e62897

File tree

1 file changed

+99
-66
lines changed
  • cpp/misra/test/rules/RULE-10-2-2

1 file changed

+99
-66
lines changed

cpp/misra/test/rules/RULE-10-2-2/test.cpp

Lines changed: 99 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,115 @@ static int32_t G1 = 1;
55
static int32_t G2 = 2;
66

77
/* ========== 2. Global scope enums ========== */
8-
enum E_Global1 : int32_t { V1, V2, V3 }; // NON_COMPLIANT: unscoped at global scope
9-
enum { GlobalAnon1, GlobalAnon2 }; // NON_COMPLIANT: unscoped anonymous at global scope
8+
enum E_Global1 : int32_t {
9+
V1,
10+
V2,
11+
V3
12+
}; // NON_COMPLIANT: unscoped at global scope
13+
enum {
14+
GlobalAnon1,
15+
GlobalAnon2
16+
}; // NON_COMPLIANT: unscoped anonymous at global scope
1017
enum class E_Global2 : int32_t { V1, V2 }; // COMPLIANT: scoped enum
1118

1219
/* ========== 3. Nested namespaces ========== */
1320
namespace N1 {
14-
static int32_t N1_V1 = 1;
21+
static int32_t N1_V1 = 1;
1522

16-
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in namespace + hides ::G1
17-
enum { N1_Anon1, N1_Anon2 }; // NON_COMPLIANT: unscoped anonymous in namespace
18-
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
23+
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in namespace + hides ::G1
24+
enum { N1_Anon1, N1_Anon2 }; // NON_COMPLIANT: unscoped anonymous in namespace
25+
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
1926

20-
namespace N2 {
21-
static int32_t N2_V1 = 1;
27+
namespace N2 {
28+
static int32_t N2_V1 = 1;
2229

23-
enum E3 : int32_t { N1_V1 }; // NON_COMPLIANT: unscoped in namespace + hides N1::N1_V1
24-
enum E4 : int32_t { G2 }; // NON_COMPLIANT: unscoped in namespace + hides ::G2
25-
enum class E5 : int32_t { N1_V1, G2 }; // COMPLIANT: scoped enum
26-
}
27-
}
30+
enum E3 : int32_t {
31+
N1_V1
32+
}; // NON_COMPLIANT: unscoped in namespace + hides N1::N1_V1
33+
enum E4 : int32_t { G2 }; // NON_COMPLIANT: unscoped in namespace + hides ::G2
34+
enum class E5 : int32_t { N1_V1, G2 }; // COMPLIANT: scoped enum
35+
} // namespace N2
36+
} // namespace N1
2837

2938
/* ========== 4. Anonymous namespace ========== */
3039
namespace {
31-
enum E_Anon1 : int32_t { V1, V2 }; // NON_COMPLIANT: unscoped in anonymous namespace
32-
enum { AnonAnon1, AnonAnon2 }; // NON_COMPLIANT: unscoped anonymous in anonymous namespace
33-
enum class E_Anon2 : int32_t { V1 }; // COMPLIANT: scoped enum
34-
}
40+
enum E_Anon1 : int32_t {
41+
V1,
42+
V2
43+
}; // NON_COMPLIANT: unscoped in anonymous namespace
44+
enum {
45+
AnonAnon1,
46+
AnonAnon2
47+
}; // NON_COMPLIANT: unscoped anonymous in anonymous namespace
48+
enum class E_Anon2 : int32_t { V1 }; // COMPLIANT: scoped enum
49+
} // namespace
3550

3651
/* ========== 5. Anonymous namespace inside named namespace ========== */
3752
namespace N3 {
38-
static int32_t N3_V1 = 1;
53+
static int32_t N3_V1 = 1;
3954

40-
namespace {
41-
enum E1 : int32_t { N3_V1 }; // NON_COMPLIANT: unscoped + hides N3::N3_V1
42-
enum class E2 : int32_t { N3_V1 }; // COMPLIANT: scoped enum
43-
}
44-
}
55+
namespace {
56+
enum E1 : int32_t { N3_V1 }; // NON_COMPLIANT: unscoped + hides N3::N3_V1
57+
enum class E2 : int32_t { N3_V1 }; // COMPLIANT: scoped enum
58+
} // namespace
59+
} // namespace N3
4560

4661
/* ========== 6. Nested classes ========== */
4762
class C1 {
4863
static int32_t C1_V1;
4964

50-
enum E1 { G1 }; // COMPLIANT: unscoped in class (exception) + hides ::G1
51-
enum { C1_Anon1, C1_Anon2 }; // COMPLIANT: unscoped anonymous in class (exception)
52-
enum class E2 { G1 }; // COMPLIANT: scoped enum
65+
enum E1 { G1 }; // COMPLIANT: unscoped in class (exception) + hides ::G1
66+
enum {
67+
C1_Anon1,
68+
C1_Anon2
69+
}; // COMPLIANT: unscoped anonymous in class (exception)
70+
enum class E2 { G1 }; // COMPLIANT: scoped enum
5371

5472
class C2 {
55-
enum E3 { C1_V1 }; // COMPLIANT: unscoped in nested class (exception)
56-
enum E4 { G2 }; // COMPLIANT: unscoped in nested class (exception) + hides ::G2
73+
enum E3 { C1_V1 }; // COMPLIANT: unscoped in nested class (exception)
74+
enum E4 {
75+
G2
76+
}; // COMPLIANT: unscoped in nested class (exception) + hides ::G2
5777

5878
struct S1 {
59-
enum E5 { C1_V1 }; // COMPLIANT: unscoped in struct (exception)
60-
enum class E6 { C1_V1 }; // COMPLIANT: scoped enum
79+
enum E5 { C1_V1 }; // COMPLIANT: unscoped in struct (exception)
80+
enum class E6 { C1_V1 }; // COMPLIANT: scoped enum
6181
};
6282
};
6383
};
6484

6585
/* ========== 7. Struct at global scope ========== */
6686
struct S_Global {
67-
enum E1 { G1 }; // COMPLIANT: unscoped in struct (exception)
68-
enum { S_Anon1, S_Anon2 }; // COMPLIANT: unscoped anonymous in struct (exception)
69-
enum class E2 { G1 }; // COMPLIANT: scoped enum
87+
enum E1 { G1 }; // COMPLIANT: unscoped in struct (exception)
88+
enum {
89+
S_Anon1,
90+
S_Anon2
91+
}; // COMPLIANT: unscoped anonymous in struct (exception)
92+
enum class E2 { G1 }; // COMPLIANT: scoped enum
7093
};
7194

7295
/* ========== 8. Class inside namespace ========== */
7396
namespace N4 {
74-
static int32_t N4_V1 = 1;
97+
static int32_t N4_V1 = 1;
7598

76-
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in namespace
99+
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in namespace
77100

78-
class C1 {
79-
enum E2 { N4_V1 }; // COMPLIANT: unscoped in class (exception) + hides N4::N4_V1
80-
enum E3 { G2 }; // COMPLIANT: unscoped in class (exception) + hides ::G2
81-
enum class E4 { N4_V1, G2 }; // COMPLIANT: scoped enum
82-
};
83-
}
101+
class C1 {
102+
enum E2 {
103+
N4_V1
104+
}; // COMPLIANT: unscoped in class (exception) + hides N4::N4_V1
105+
enum E3 { G2 }; // COMPLIANT: unscoped in class (exception) + hides ::G2
106+
enum class E4 { N4_V1, G2 }; // COMPLIANT: scoped enum
107+
};
108+
} // namespace N4
84109

85110
/* ========== 9. Function body ========== */
86111
void f1() {
87112
int F1_V1 = 1;
88113

89-
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in function + hides ::G1
90-
enum { F1_Anon1, F1_Anon2 }; // NON_COMPLIANT: unscoped anonymous in function
91-
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
114+
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in function + hides ::G1
115+
enum { F1_Anon1, F1_Anon2 }; // NON_COMPLIANT: unscoped anonymous in function
116+
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
92117
}
93118

94119
/* ========== 10. Nested blocks ========== */
@@ -98,11 +123,15 @@ void f2() {
98123
{
99124
int F2_V2 = 2;
100125

101-
enum E1 : int32_t { F2_V1 }; // NON_COMPLIANT: unscoped in block + hides outer F2_V1
102-
enum E2 : int32_t { G2 }; // NON_COMPLIANT: unscoped in block + hides ::G2
126+
enum E1 : int32_t {
127+
F2_V1
128+
}; // NON_COMPLIANT: unscoped in block + hides outer F2_V1
129+
enum E2 : int32_t { G2 }; // NON_COMPLIANT: unscoped in block + hides ::G2
103130

104131
{
105-
enum E3 : int32_t { F2_V2 }; // NON_COMPLIANT: unscoped in nested block + hides outer F2_V2
132+
enum E3 : int32_t {
133+
F2_V2
134+
}; // NON_COMPLIANT: unscoped in nested block + hides outer F2_V2
106135
enum class E4 : int32_t { F2_V1, F2_V2, G1 }; // COMPLIANT: scoped enum
107136
}
108137
}
@@ -113,40 +142,44 @@ void f3() {
113142
int F3_V1 = 1;
114143

115144
class LocalC1 {
116-
enum E1 { F3_V1 }; // COMPLIANT: unscoped in local class (exception)
117-
enum E2 { G1 }; // COMPLIANT: unscoped in local class (exception) + hides ::G1
118-
enum { Local_Anon1 }; // COMPLIANT: unscoped anonymous in local class (exception)
119-
enum class E3 { F3_V1, G1 }; // COMPLIANT: scoped enum
145+
enum E1 { F3_V1 }; // COMPLIANT: unscoped in local class (exception)
146+
enum E2 {
147+
G1
148+
}; // COMPLIANT: unscoped in local class (exception) + hides ::G1
149+
enum {
150+
Local_Anon1
151+
}; // COMPLIANT: unscoped anonymous in local class (exception)
152+
enum class E3 { F3_V1, G1 }; // COMPLIANT: scoped enum
120153
};
121154
}
122155

123156
/* ========== 12. Lambda body ========== */
124157
auto lambda1 = []() {
125-
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in lambda body
126-
enum { Lambda_Anon1 }; // NON_COMPLIANT: unscoped anonymous in lambda body
127-
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
158+
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in lambda body
159+
enum { Lambda_Anon1 }; // NON_COMPLIANT: unscoped anonymous in lambda body
160+
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
128161
};
129162

130163
/* ========== 13. Nested lambdas ========== */
131164
namespace N5 {
132-
auto lambda2 = []() {
133-
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in lambda body
165+
auto lambda2 = []() {
166+
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in lambda body
134167

135-
auto nested_lambda = []() {
136-
enum E2 : int32_t { G2 }; // NON_COMPLIANT: unscoped in nested lambda body
137-
enum class E3 : int32_t { G1, G2 }; // COMPLIANT: scoped enum
138-
};
168+
auto nested_lambda = []() {
169+
enum E2 : int32_t { G2 }; // NON_COMPLIANT: unscoped in nested lambda body
170+
enum class E3 : int32_t { G1, G2 }; // COMPLIANT: scoped enum
139171
};
140-
}
172+
};
173+
} // namespace N5
141174

142175
/* ========== 14. Lambda inside class ========== */
143176
class C3 {
144177
static inline auto member_lambda = []() {
145-
enum E1 : int32_t { G1 }; // NON_COMPLIANT: unscoped in lambda body (not class scope!)
146-
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
178+
enum E1 : int32_t {
179+
G1
180+
}; // NON_COMPLIANT: unscoped in lambda body (not class scope!)
181+
enum class E2 : int32_t { G1 }; // COMPLIANT: scoped enum
147182
};
148183
};
149184

150-
int main() {
151-
return 0;
152-
}
185+
int main() { return 0; }

0 commit comments

Comments
 (0)