C and C++


LANG.LAMBDA.MRT : Lambda Has No Return Type

Summary

A lambda expression has non-void return type, but the return type is not explicitly specified.

Properties

Class Name Lambda Has No Return Type
Significance style
Mnemonic LANG.LAMBDA.MRT
Categories
AUTOSARC++14 AUTOSARC++14:A5-1-6 Return type of a non-void return type lambda expression should be explicitly specified.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Lambda Has No Return Type"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

int lambda_returntype(int i){
   int rv = 0;
  
   auto lambda_void = [&rv](int x){                          // ok: void return type
                        rv += x;
                      };

   auto lambda_nortype = [](int x){   // 'Lambda Has No Return Type' warning issued here
                           return x+5;
                         };

   auto lambda_rtype =  [](int x)->int{                      // ok: return type explicitly specified
                        return x+6;
                      };

   lambda_void(i);
   return rv + lambda_nortype(i) + lambda_rtype(i);
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.