Skip to content

Commit 92c7dac

Browse files
committed
Rule 7.0.5: Add pointer tests (should be ignored)
1 parent aac2dc2 commit 92c7dac

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,41 @@ void test_floating_point_conversions() {
199199
l1 += l2; // NON_COMPLIANT - l2 -> floating
200200
l1 *= l2; // NON_COMPLIANT - l2 -> floating
201201
l1 /= l2; // NON_COMPLIANT - l2 -> floating
202+
}
203+
204+
void test_pointer_arithmetic() {
205+
int l1[10];
206+
std::uint8_t l2 = 5;
207+
std::uint16_t l3 = 2;
208+
std::int8_t l4 = 3;
209+
std::int32_t l5 = 1;
210+
int *l6 = l1;
211+
212+
l1 + l2; // COMPLIANT - rule does not apply to pointer arithmetic
213+
l1 + l3; // COMPLIANT - rule does not apply to pointer arithmetic
214+
l1 + l4; // COMPLIANT - rule does not apply to pointer arithmetic
215+
l1 + l5; // COMPLIANT - rule does not apply to pointer arithmetic
216+
l6 + l2; // COMPLIANT - rule does not apply to pointer arithmetic
217+
l6 + l3; // COMPLIANT - rule does not apply to pointer arithmetic
218+
219+
l1 - l2; // COMPLIANT - rule does not apply to pointer arithmetic
220+
l6 - l3; // COMPLIANT - rule does not apply to pointer arithmetic
221+
222+
l6 - l1; // COMPLIANT - rule does not apply to pointer arithmetic
223+
}
224+
225+
void test_pointer_assignment_arithmetic() {
226+
int l1[10];
227+
std::uint8_t l2 = 5;
228+
std::uint16_t l3 = 2;
229+
std::int8_t l4 = 3;
230+
int *l5 = l1;
231+
232+
l5 += l2; // COMPLIANT - rule does not apply to pointer arithmetic
233+
l5 += l3; // COMPLIANT - rule does not apply to pointer arithmetic
234+
l5 += l4; // COMPLIANT - rule does not apply to pointer arithmetic
235+
236+
l5 -= l2; // COMPLIANT - rule does not apply to pointer arithmetic
237+
l5 -= l3; // COMPLIANT - rule does not apply to pointer arithmetic
238+
l5 -= l4; // COMPLIANT - rule does not apply to pointer arithmetic
202239
}

0 commit comments

Comments
 (0)