`M6-5-3`: Triggered when loop counter is passed as const ref
nbusser-sr opened this issue · 2 comments
nbusser-sr commented
Affected rules
M6-5-3:cpp/autosar/loop-counter-modified-within-statement
Rule 6–5–3 (Required)
The loop-counter shall not be modified within condition
or statement.
Description
When passing a loop counter to a function as const ref, M6-5-3 is triggered.
NB: It is also triggered when passed as a mutable ref, but the function never uses the ref. This is less problematic since you should not give a mutable ref argument which is never modified.
Example
std::size_t const_ref(const std::size_t& iRef) {
return iRef;
}
std::size_t ref(const std::size_t& iRef) {
return iRef;
}
std::size_t copy(const std::size_t iRef) {
return iRef;
}
for (std::size_t i{0}; i < 5; ++i) {
const_ref(i); // Triggers M6-5-3
ref(i); // Triggers M6-5-3
copy(i); // Ok
}lcartey commented
Thanks! This should be relatively straight-forward to fix.
Note for future implementor, we need to modify Loops.qll to change:
loopCounterAccess.isAddressOfAccess()to
loopCounterAccess.isAddressOfAccessNonConst()fjatWbyT commented
I think this one is fixed now.