Skip to content

Commit a7ce6f5

Browse files
committed
Rule 7.0.5: Expand test cases
- More shift testing - Mixed signed/unsigned
1 parent f50baa9 commit a7ce6f5

File tree

2 files changed

+111
-33
lines changed

2 files changed

+111
-33
lines changed

cpp/misra/test/rules/RULE-7-0-5/NoSignednessChangeFromPromotion.expected

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,46 @@
2222
| test.cpp:48:9:48:10 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
2323
| test.cpp:49:9:49:10 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
2424
| test.cpp:50:9:50:10 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
25-
| test.cpp:62:3:62:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
26-
| test.cpp:63:3:63:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
27-
| test.cpp:64:3:64:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
28-
| test.cpp:65:3:65:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
29-
| test.cpp:66:3:66:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
30-
| test.cpp:67:3:67:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
31-
| test.cpp:69:3:69:4 | l3 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
32-
| test.cpp:69:8:69:9 | l4 | Usual arithmetic conversion from 'uint16_t' to 'int' changes signedness. |
33-
| test.cpp:70:3:70:4 | l3 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
34-
| test.cpp:70:8:70:9 | l4 | Usual arithmetic conversion from 'uint16_t' to 'int' changes signedness. |
35-
| test.cpp:80:8:80:9 | l2 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
36-
| test.cpp:80:13:80:14 | l4 | Integer promotion from 'uint16_t' to 'int' changes signedness. |
37-
| test.cpp:87:3:87:4 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
38-
| test.cpp:88:3:88:4 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
39-
| test.cpp:98:4:98:5 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
40-
| test.cpp:100:4:100:5 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
41-
| test.cpp:102:4:102:5 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
42-
| test.cpp:141:9:141:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes signedness. |
43-
| test.cpp:141:9:141:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes type category. |
44-
| test.cpp:142:9:142:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes signedness. |
45-
| test.cpp:142:9:142:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes type category. |
46-
| test.cpp:143:9:143:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes signedness. |
47-
| test.cpp:143:9:143:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes type category. |
25+
| test.cpp:62:3:62:4 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
26+
| test.cpp:63:3:63:4 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
27+
| test.cpp:64:3:64:4 | l2 | Integer promotion from 'uint16_t' to 'int' changes signedness. |
28+
| test.cpp:65:3:65:4 | l2 | Integer promotion from 'uint16_t' to 'int' changes signedness. |
29+
| test.cpp:68:9:68:10 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
30+
| test.cpp:69:9:69:10 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
31+
| test.cpp:79:10:79:11 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
32+
| test.cpp:80:10:80:11 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
33+
| test.cpp:91:3:91:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
34+
| test.cpp:92:3:92:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
35+
| test.cpp:93:3:93:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
36+
| test.cpp:94:3:94:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
37+
| test.cpp:95:3:95:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
38+
| test.cpp:96:3:96:4 | l1 | Usual arithmetic conversion from 'int32_t' to 'unsigned int' changes signedness. |
39+
| test.cpp:98:3:98:4 | l3 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
40+
| test.cpp:98:8:98:9 | l4 | Usual arithmetic conversion from 'uint16_t' to 'int' changes signedness. |
41+
| test.cpp:99:3:99:4 | l3 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
42+
| test.cpp:99:8:99:9 | l4 | Usual arithmetic conversion from 'uint16_t' to 'int' changes signedness. |
43+
| test.cpp:109:8:109:9 | l2 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
44+
| test.cpp:109:13:109:14 | l4 | Integer promotion from 'uint16_t' to 'int' changes signedness. |
45+
| test.cpp:117:4:117:5 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
46+
| test.cpp:119:4:119:5 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
47+
| test.cpp:121:4:121:5 | l1 | Integer promotion from 'uint8_t' to 'int' changes signedness. |
48+
| test.cpp:164:8:164:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
49+
| test.cpp:165:8:165:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
50+
| test.cpp:166:7:166:8 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
51+
| test.cpp:167:8:167:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
52+
| test.cpp:168:8:168:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
53+
| test.cpp:169:8:169:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
54+
| test.cpp:170:8:170:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
55+
| test.cpp:171:8:171:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
56+
| test.cpp:173:8:173:9 | l4 | Usual arithmetic conversion from 'uint16_t' to 'int' changes signedness. |
57+
| test.cpp:174:8:174:9 | l4 | Usual arithmetic conversion from 'uint16_t' to 'int' changes signedness. |
58+
| test.cpp:175:7:175:8 | l4 | Usual arithmetic conversion from 'uint16_t' to 'int' changes signedness. |
59+
| test.cpp:177:8:177:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
60+
| test.cpp:178:8:178:9 | l2 | Usual arithmetic conversion from 'uint8_t' to 'int' changes signedness. |
61+
| test.cpp:179:9:179:10 | l4 | Usual arithmetic conversion from 'uint16_t' to 'int' changes signedness. |
62+
| test.cpp:199:9:199:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes signedness. |
63+
| test.cpp:199:9:199:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes type category. |
64+
| test.cpp:200:9:200:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes signedness. |
65+
| test.cpp:200:9:200:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes type category. |
66+
| test.cpp:201:9:201:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes signedness. |
67+
| test.cpp:201:9:201:10 | l2 | Usual arithmetic conversion from 'uint32_t' to 'float' changes type category. |

cpp/misra/test/rules/RULE-7-0-5/test.cpp

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,35 @@ void test_assignment_operations() {
5353
l1 += l3; // COMPLIANT - l1 -> unsigned int
5454
}
5555

56+
void test_shift_operations() {
57+
std::uint8_t l1 = 5;
58+
std::uint16_t l2 = 100;
59+
std::uint32_t l3 = 1000;
60+
std::int16_t l4;
61+
62+
l1 << 2; // NON_COMPLIANT - l1 -> signed int
63+
l1 >> 1; // NON_COMPLIANT - l1 -> signed int
64+
l2 << 2; // NON_COMPLIANT - l2 -> signed int
65+
l2 >> 1; // NON_COMPLIANT - l2 -> signed int
66+
l3 << 2; // COMPLIANT
67+
l3 >> 1; // COMPLIANT
68+
l3 << l1; // NON_COMPLIANT - l1 -> signed int
69+
l3 >> l1; // NON_COMPLIANT - l1 -> signed int
70+
l3 << l4; // COMPLIANT
71+
l3 >> l4; // COMPLIANT
72+
73+
l1 <<= 2; // NON_COMPLIANT - l1 -> signed int
74+
l1 >>= 1; // NON_COMPLIANT - l1 -> signed int
75+
l2 <<= 2; // NON_COMPLIANT - l2 -> signed int
76+
l2 >>= 1; // NON_COMPLIANT - l2 -> signed int
77+
l3 <<= 2; // COMPLIANT
78+
l3 >>= 1; // COMPLIANT
79+
l3 <<= l1; // NON_COMPLIANT - l1 -> signed int
80+
l3 >>= l1; // NON_COMPLIANT - l1 -> signed int
81+
l3 <<= l4; // COMPLIANT
82+
l3 >>= l4; // COMPLIANT
83+
}
84+
5685
void test_comparison_operations() {
5786
std::int32_t l1 = -1000;
5887
std::uint32_t l2 = 1000;
@@ -80,16 +109,6 @@ void test_conditional_operator() {
80109
l1 ? l2 : l4; // NON_COMPLIANT - l2 and l4 -> signed int
81110
}
82111

83-
void test_shift_operations() {
84-
std::uint8_t l1 = 5;
85-
std::uint32_t l2 = 1000;
86-
87-
l1 << 2; // NON_COMPLIANT - l1 -> signed int
88-
l1 >> 1; // NON_COMPLIANT - l1 -> signed int
89-
l2 << 2; // COMPLIANT
90-
l2 >> 1; // COMPLIANT
91-
}
92-
93112
void test_unary_operations() {
94113
std::uint8_t l1 = 5;
95114
std::uint32_t l2 = 1000;
@@ -121,6 +140,45 @@ void test_array_subscript() {
121140
l1[l2]; // COMPLIANT - rule does not apply
122141
}
123142

143+
void test_logical_operators() {
144+
std::uint8_t l1 = 5;
145+
std::uint8_t l2 = 10;
146+
std::uint16_t l3 = 100;
147+
std::int8_t l4 = -5;
148+
bool l5 = true;
149+
150+
l1 &&l2; // COMPLIANT - rule does not apply to logical operators
151+
l1 || l2; // COMPLIANT - rule does not apply to logical operators
152+
l1 &&l3; // COMPLIANT - rule does not apply to logical operators
153+
l4 &&l1; // COMPLIANT - rule does not apply to logical operators
154+
l5 &&l1; // COMPLIANT - rule does not apply to logical operators
155+
l1 &&l5; // COMPLIANT - rule does not apply to logical operators
156+
}
157+
158+
void test_mixed_signed_unsigned_arithmetic() {
159+
std::int8_t l1 = -5;
160+
std::uint8_t l2 = 10;
161+
std::int16_t l3 = -100;
162+
std::uint16_t l4 = 200;
163+
164+
l1 + l2; // NON_COMPLIANT - l1 and l2 -> signed int
165+
l1 - l2; // NON_COMPLIANT - l1 and l2 -> signed int
166+
l1 *l2; // NON_COMPLIANT - l1 and l2 -> signed int
167+
l1 / l2; // NON_COMPLIANT - l1 and l2 -> signed int
168+
l1 % l2; // NON_COMPLIANT - l1 and l2 -> signed int
169+
l1 & l2; // NON_COMPLIANT - l1 and l2 -> signed int
170+
l1 | l2; // NON_COMPLIANT - l1 and l2 -> signed int
171+
l1 ^ l2; // NON_COMPLIANT - l1 and l2 -> signed int
172+
173+
l3 + l4; // NON_COMPLIANT - l3 and l4 -> signed int
174+
l3 - l4; // NON_COMPLIANT - l3 and l4 -> signed int
175+
l3 *l4; // NON_COMPLIANT - l3 and l4 -> signed int
176+
177+
l1 < l2; // NON_COMPLIANT - l1 and l2 -> signed int
178+
l1 > l2; // NON_COMPLIANT - l1 and l2 -> signed int
179+
l3 == l4; // NON_COMPLIANT - l3 and l4 -> signed int
180+
}
181+
124182
void test_exception_compile_time_constants() {
125183
std::uint32_t l1 = 1000;
126184
float l2 = 3.14f;

0 commit comments

Comments
 (0)