Skip to content

M6-5-3: Triggered when loop counter is passed as const ref #755

Closed
@nbusser-sr

Description

@nbusser-sr

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-MediumStandard-AUTOSARfalse positive/false negativeAn issue related to observed false positives or false negatives.user-reportIssue reported by an end user of CodeQL Coding Standards

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions