C ++ 11 lambdas capture by reference is trivially destructible

I would like to know if there are following memory leaks or not (defined by the standard)

...
jmp_buf env;
if(setjmp(env) == 0) {
    auto lambda = [&] () {
        ... 
        longjmp(env, 1);
    };
    lambda();
}

which boils down to the fact that lambdas that grabbed the link has a trivial destructor (I think)?

I know that this is probably wicked, but still needs to be done.

+4
source share
1 answer

It is implementation specific. You can reasonably expect this to be true, but here is what the standard says (N4140, [expr.prim.lambda] / 3, my hit):

, , , :
 - / ,
 - , ( 9),
 - ( 9),
 - POD ( 9).

[class]/3

- , :  - (12.8),
 - (12.8),
 - (13.5.3, 12.8),
 - (13.5.3, 12.8)
 - (12.4).

, .

, :

auto lambda = [&]{ /*...*/ };
static_assert(std::is_trivially_destructible<decltype(lambda)>::value, "Lambda isn't trivially destructible");
+4

Source: https://habr.com/ru/post/1585082/


All Articles