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
#2
When the MISRA 2008 rule was written range-based for loops had not been defined, so were not considered by the rule. It was adopted by Autosar unmodified.

The view of the committee is that use of range-based for loops with objects of array type should be compliant with this rule.
Posted by and on behalf of
the MISRA C++ Working Group
Reply
#3
Great, thanks for the clarification!
Reply
#4
This thread is now closed.

For discussion on related topics, please start a new thread
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)