Skip to content

Commit 06eddfa

Browse files
committed
Rule 7.0.6: Add a test case for non-numeric (not covered)
1 parent 01b517d commit 06eddfa

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include <cstdint>
2+
#include <string>
3+
4+
// Test non-numeric type categories - these should not trigger rule violations
5+
void test_non_numeric_type_categories() {
6+
// Character category types
7+
char l1 = 'a';
8+
wchar_t l2 = L'b';
9+
char16_t l3 = u'c';
10+
char32_t l4 = U'd';
11+
12+
// Other category types
13+
bool l5 = true;
14+
void *l6 = nullptr;
15+
std::nullptr_t l7 = nullptr;
16+
17+
// Assignments between character types and numeric types
18+
// Rule should not apply since source/target involve non-numeric types
19+
std::uint8_t l8 = 42;
20+
std::int32_t l9 = 100;
21+
float l10 = 3.14f;
22+
23+
// Character to numeric - rule does not apply
24+
l8 = l1; // COMPLIANT - char is character category, not numeric
25+
l9 = l2; // COMPLIANT - wchar_t is character category, not numeric
26+
l8 = l3; // COMPLIANT - char16_t is character category, not numeric
27+
l9 = l4; // COMPLIANT - char32_t is character category, not numeric
28+
l10 = l1; // COMPLIANT - char is character category, not numeric
29+
30+
// Numeric to character - rule does not apply
31+
l1 = l8; // COMPLIANT - char is character category, not numeric
32+
l2 = l9; // COMPLIANT - wchar_t is character category, not numeric
33+
l3 = l8; // COMPLIANT - char16_t is character category, not numeric
34+
l4 = l9; // COMPLIANT - char32_t is character category, not numeric
35+
l1 = l10; // COMPLIANT - char is character category, not numeric
36+
37+
// Other category to numeric - rule does not apply
38+
l8 = l5; // COMPLIANT - bool is other category, not numeric
39+
l9 = l5; // COMPLIANT - bool is other category, not numeric
40+
l10 = l5; // COMPLIANT - bool is other category, not numeric
41+
42+
// Numeric to other category - rule does not apply
43+
l5 = l8; // COMPLIANT - bool is other category, not numeric
44+
l5 = l9; // COMPLIANT - bool is other category, not numeric
45+
l5 = l10; // COMPLIANT - bool is other category, not numeric
46+
47+
// Character to character - rule does not apply
48+
l1 = l2; // COMPLIANT - both character category, not numeric
49+
l3 = l4; // COMPLIANT - both character category, not numeric
50+
l1 = l3; // COMPLIANT - both character category, not numeric
51+
52+
// Other to other - rule does not apply
53+
std::nullptr_t l11 = l7; // COMPLIANT - both other category, not numeric
54+
l6 = l7; // COMPLIANT - both other category, not numeric
55+
56+
// Character to other - rule does not apply
57+
l5 = l1; // COMPLIANT - neither is numeric category
58+
l6 = nullptr; // COMPLIANT - neither is numeric category
59+
60+
// Other to character - rule does not apply
61+
l1 = l5; // COMPLIANT - neither is numeric category
62+
}
63+
64+
// Test function parameters with non-numeric types
65+
void f15(char l1) {}
66+
void f16(bool l1) {}
67+
void f17(wchar_t l1) {}
68+
69+
void test_non_numeric_function_parameters() {
70+
std::uint8_t l1 = 42;
71+
std::int32_t l2 = 100;
72+
char l3 = 'x';
73+
bool l4 = true;
74+
wchar_t l5 = L'y';
75+
76+
// Function calls with non-numeric parameters - rule does not apply
77+
f15(l1); // COMPLIANT - parameter is character category, not numeric
78+
f15(l2); // COMPLIANT - parameter is character category, not numeric
79+
f15(l3); // COMPLIANT - parameter is character category, not numeric
80+
81+
f16(l1); // COMPLIANT - parameter is other category, not numeric
82+
f16(l2); // COMPLIANT - parameter is other category, not numeric
83+
f16(l4); // COMPLIANT - parameter is other category, not numeric
84+
85+
f17(l1); // COMPLIANT - parameter is character category, not numeric
86+
f17(l2); // COMPLIANT - parameter is character category, not numeric
87+
f17(l5); // COMPLIANT - parameter is character category, not numeric
88+
}
89+
90+
// Test references to non-numeric types
91+
void test_non_numeric_references() {
92+
char l1 = 'a';
93+
bool l2 = true;
94+
wchar_t l3 = L'b';
95+
std::uint8_t l4 = 42;
96+
std::int32_t l5 = 100;
97+
98+
char &l6 = l1;
99+
bool &l7 = l2;
100+
wchar_t &l8 = l3;
101+
102+
// Assignments involving references to non-numeric types - rule does not apply
103+
l4 = l6; // COMPLIANT - reference to character category, not numeric
104+
l5 = l7; // COMPLIANT - reference to other category, not numeric
105+
l4 = l8; // COMPLIANT - reference to character category, not numeric
106+
107+
l6 = l4; // COMPLIANT - reference to character category, not numeric
108+
l7 = l5; // COMPLIANT - reference to other category, not numeric
109+
l8 = l4; // COMPLIANT - reference to character category, not numeric
110+
}
111+
112+
// Test bit-fields with non-numeric types (though these are rare in practice)
113+
struct NonNumericBitFields {
114+
bool m1 : 1; // Other category
115+
char m2 : 7; // Character category
116+
wchar_t m3 : 16; // Character category
117+
};
118+
119+
void test_non_numeric_bitfields() {
120+
NonNumericBitFields l1;
121+
std::uint8_t l2 = 42;
122+
std::int32_t l3 = 100;
123+
bool l4 = true;
124+
char l5 = 'x';
125+
126+
// Assignments to/from non-numeric bit-fields - rule does not apply
127+
l1.m1 = l2; // COMPLIANT - bit-field is other category, not numeric
128+
l1.m1 = l4; // COMPLIANT - bit-field is other category, not numeric
129+
l1.m2 = l2; // COMPLIANT - bit-field is character category, not numeric
130+
l1.m2 = l5; // COMPLIANT - bit-field is character category, not numeric
131+
l1.m3 = l3; // COMPLIANT - bit-field is character category, not numeric
132+
133+
l2 = l1.m1; // COMPLIANT - bit-field is other category, not numeric
134+
l4 = l1.m1; // COMPLIANT - bit-field is other category, not numeric
135+
l2 = l1.m2; // COMPLIANT - bit-field is character category, not numeric
136+
l5 = l1.m2; // COMPLIANT - bit-field is character category, not numeric
137+
l3 = l1.m3; // COMPLIANT - bit-field is character category, not numeric
138+
}

0 commit comments

Comments
 (0)