This is Undefined Behavior .
In paragraph 5.2.2 / 4 of the C ++ 11 standard on expressions for calling functions and initializing their parameters:
[...] The lifetime of the parameter ends when the function in which it is defined return . The initialization and destruction of each parameter occurs in the context of the calling function. [...]
Therefore, your lambda will store a link that becomes dangling as soon as the function call returns.
In this case, the implementations are free (and probably) for creating functional parameters at the same address for each function call, which is probably the reason that you are seeing the expected result.
However, this standard requirement is not provided, so you should not rely on it (if that were the case, your code would be legal due to 3.8 / 7).
Andy prowl
source share