AUTOSAR rule A5-0-4 states
Pointer arithmetic shall not be used with pointers to non-finalclasses.
It provides the following rationale:
Pointer arithmetic is only well defined if the pointed-to type of thepointer equals the element type of the array it points into, otherwisethe behavior is undefined. This property can only be guaranteed if thepointer operand is a pointer to non-class type or a pointer to finalclass type.
It then gives some examples of compliance and non-compliance. One of the non-compliances has me puzzled:
void Foo(Base *start, size_t len){ // Non-Compliant: pointer arithmetic on non-final pointer type for (Base *iter = start; iter != start + len; ++iter) { iter->Do(); }}
However unlikely it is that anyone would use a plain C-array to store polymorphic pointers, it's in the very fabric of the C++ language.
So my gut feeling is that there is nothing wrong with the above code.
Perhaps I am mistaken in this belief.Or perhaps I am completely missing the point that this AUTOSAR rule is trying to convey to the reader.
Can someone explain it better than the AUTOSAR document does?
See also AUTOSAR rule A5-0-4, which gives the full code used in the example.