AutosarC++17_03-A5.1.6ΒΆ

Return type of a non-void return type lambda expression should be explicitly specified

Required inputs: IR

Rationale

If a non-void return type lambda expression does not specify its return type, then it may be confusing which type it returns. It leads to developers confusion.

Note that, while the return type is specified, implicit conversion between type of returned value and return type specified in the lambda expression may occur. This problem should not be ignored.

Example
// $Id: A5-1-6.cpp 271687 2017-03-23 08:57:35Z piotr.tanski $
#include <cstdint>
void fn() noexcept {
auto lambda1 = []() -> std::uint8_t {
std::uint8_t ret = 0U;
// ...
return ret;
}; // Compliant
auto lambda2 = []() {
// ...
return 0U;
};                  // Non-compliant - returned type is not specified
auto x = lambda1(); // Type of x is std::uint8_t
auto y = lambda2(); // What is the type of y?
}
See Also
  • none

Possible Messages

Key

Text

Severity

Disabled

missing_explicit_return

Add an explicit return type for the lambda.

None

False

Options