Skip to content

A4-7-1: Guard using "." operator getting ignored #600

Open
@nbusser

Description

@nbusser

Affected rules

  • A4-7-1

Description

Changing a class/struct's member value with an arithmetic expression triggers a A4-7-1 warning, despite using an appropriate type guard (example function false_positive).
I have to workaround it by destructuring my member (example function true_negative).

It seems that the "." operator is badly supported.

Triggered warning is cpp/autosar/integer-expression-lead-to-data-loss.

Example

struct A {
  std::int32_t s32;
}

void false_positive(A a) {
  if (a.s32 > std::numeric_limits<std::int32_t>::min()) {
    // Is supposed to be compliant with A4-7-1, but CodeQL reports a warning
    --a.s32;
  }
}

void true_negative(A a) {
  auto s32 = a.s32;
  if (s32 > std::numeric_limits<std::int32_t>::min()) {
    // Compliant with A4-7-1
    --s32;
  }
  a.s32 = s32;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty-HighA false positive or false negative report which is expected to take 1+ week 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

    Triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions