Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC++2023-8.1.2 (C++ only)

In this section:
Synopsis

(Advisory) Variables should be captured explicitly in a non-transient lambda

Enabled by default

No

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Explicit capture of variables helps to clarify its dependencies

Coding standards

This check does not correspond to any coding standard rules.

Code examples

The following code example fails the check and will give a warning:

void example(int n) {
  auto a1 = [=]() { return n; }; // Non-Compliant, implicit capture of n.
}

The following code example passes the check and will not give a warning about this issue:

void example(int n) {
  auto a1 = [&n]() { return n; }; // Compliant
}