AUTOSAR C++14 Rule A5-1-9
Identical unnamed lambda expressions shall be replaced with a named function or a named lambda expression
Since R2020b
Description
Rule Definition
Identical unnamed lambda expressions shall be replaced with a named function or a named lambda expression.
Rationale
When you reuse an unnamed lambda expression, you insert the body of that lambda expression wherever you invoke it in your code. This code duplication might result in maintainability issues when you make changes, as you might misidentify which lambda expressions are identical when applying those changes. The code duplication also decreases the readability of your code.
Polyspace Implementation
After the first use of an unnamed lambda expression, Polyspace® flags each subsequent uses of an identical lambda expression. For instance, if you reuse the same lambda expression three times, Polyspace flags the second and third uses of the lambda expression as separate violations. Polyspace also highlights the first use of the unnamed lambda expression in your source code.
Polyspace does not flag the reuse of global scope lambda expressions.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Expressions |
Category: Advisory, Automated |
Version History
Introduced in R2020b