[LLVMbugs] [Bug 21664] New: Crash while capture template std::function in lambdas

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 25 01:57:53 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21664

            Bug ID: 21664
           Summary: Crash while capture template std::function in lambdas
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kamil.rojewski at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

When trying to capture a template std::function alias in a lambda by value, I
am experiencing a crash in the resulting binary. Here is a code snippet showing
this error:

#include <functional>

template<class T>
using Callback = std::function<void (T)>;

std::function<void ()> f(const Callback<int> &callback)
{
    return [=] {
        callback(0); // crash here
    };
}

int main()
{
    auto lambda = f([](int) { });
    lambda();
    return 0;
}

This also happens when explicitly capturing "callback". To work around the
crash, the variable needs to be captured using generalized capture:

#include <functional>

template<class T>
using Callback = std::function<void (T)>;

std::function<void ()> f(const Callback<int> &callback)
{
    return [=, callback = callback] {
        callback(0);                   // no crash now
    };
}

int main()
{
    auto lambda = f([](int) { });
    lambda();
    return 0;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141125/ea1b5d45/attachment.html>


More information about the llvm-bugs mailing list