Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
M5-0-15 + range-based for loops
#1
Hi,

Our static analyzer is reporting M5-0-15 "this is using pointer arithmetic" in the following code:

Code:
int x[3] = {1,2,3};

int z = 0;
for (int y : x)  // M5-0-15 reported here
{
    z += y;
}

Most likely due to the range-based for loop expanding to an iterator-based for loop.

However, we would argue the MISRA rules apply to code written by users, not code generated by the compiler behind the scenes. 

What do you think, is the above code violating M5-0-15?

Thanks!
Reply


Messages In This Thread
M5-0-15 + range-based for loops - by cgpzs - 15-02-2022, 12:25 PM
RE: M5-0-15 + range-based for loops - by cgpzs - 23-02-2022, 11:59 AM

Forum Jump:


Users browsing this thread: 3 Guest(s)