Skip to content

A13-5-2: False positive on lambda with empty captures #178

Closed
@touhead

Description

@touhead

Affected rules

  • A13-5-2

Description

The A13-5-2 (cpp/autosar/user-defined-conversion-operators-not-defined-explicit) rule triggers on lambda with empty captures.

Example

int ref_value{0};
int other_value{0};

// ok
auto dummy_lambda = [&ref_value]() noexcept -> void { ref_value = 42; };
dummy_lambda();

// ok
auto my_lambda_1 = [&ref_value](int param) noexcept -> void {
  for (int i{0}; i < param; ++i) {
    ++ref_value;
  }
};
my_lambda_1(other_value);

// error: user-defined-conversion-operators-not-defined-explicit
auto my_lambda_2 = [](int param) noexcept -> void {
  for (int i{0}; i < param; ++i) {
    //
  }
};
my_lambda_2(other_value);

// ok
auto my_lambda_3 = [&ref_value](int param) noexcept -> void { ref_value = param; };
my_lambda_3(other_value);

Metadata

Metadata

Assignees

Labels

Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-Highfalse positive/false negativeAn issue related to observed false positives or false negatives.top-25-fpsuser-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