AUTOSAR C++14 Rule A5-1-6
Return type of a non-void return type lambda expression should be explicitly specified
Since R2020b
Description
Rule Definition
Return type of a non-void return type lambda expression should be explicitly specified.
Rationale
A compiler can deduce the return type of a lambda expression based on the type of the
return expression. For instance, if a lambda expression does not return anything, the
compiler deduces that the return type is void
.
Specifying a return type when you declare a lambda expression is optional. For non-void return type lambda expressions, if you do not specify a return type explicitly, a developer reading your code might be confused about which type the lambda expression returns.
An explicit return type also reinforces type checking when the compiler generates an implicit conversion from the type of the returned expression to the expected return type.
Polyspace Implementation
Polyspace® flags lambda expressions with non-void-return types if the return type is not specified explicitly.
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