Closed
Description
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
}