Evaluating lambda function return type

Hi All,

In an input program I have following code;

auto f = [&z](int y)->int {

return 5 * y + z;


I am trying to figure out where we build the type of the lambda expression (i.e. lambda is a function that has type, int->int)

So far I checked in “Sema::ActOnStartOfLambdaDefinition” (in SemaLambda.cpp). But still I am unable to figure out the exact location where we build the type of the lambda expression.

Can someone please help me to figure out where clang build the return type for lambda functions ?

Also where do we bind “f” to the return type of lambda function ?

Thank you


-Thejaka Amila

Lambda is built as a class with function call operator, not a function. Have a look at Sema::startLambdaDefinition, I think it does what you’re interested in. In the example you gave ‘auto f’ is bound to the lambda expression itself, not its return type. You’ll have to call it to get the return type ‘int x = f()’.