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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to