Rule A5-1-6 (advisory, implementation, automated)

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

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 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#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