File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
cpp/misra/test/rules/RULE-7-0-5 Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -199,4 +199,41 @@ void test_floating_point_conversions() {
199
199
l1 += l2; // NON_COMPLIANT - l2 -> floating
200
200
l1 *= l2; // NON_COMPLIANT - l2 -> floating
201
201
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
202
239
}
You can’t perform that action at this time.
0 commit comments