[cfe-dev] Returning a lambda with local reference

Francis Giraldeau via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 10 12:59:40 PST 2015


In the same spirit of core.StackAddressEscape, there is an instance of
problem involving a lambda that could be detected:

std::function<void ()> make_func()

{

    QString msg("local variable invalid outside of make_func");

    return [&] () { qDebug() << "lambda invalid" << msg; };

}



The function returns a lambda holding a reference to a variable on the
stack. Invoking the lambda is likely to trigger SIGSEGV. Currently, the
check returns this:

   scan-build: No bugs found.

I just thought it would be useful to share this case.

Cheers,

Francis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151110/dcc3ecce/attachment.html>


More information about the cfe-dev mailing list