C++11: std::bind crashes with lambda

Viewed 1076

Why does this code crash?

#include <iostream>
#include <functional>

int main(int argc, const char * argv[])
{
    std::function<void(int)> function = [](int)
    {
    };
    auto binding = std::bind(function, 10);

    std::function<void()> jobFunctor = binding; // crashes here with EXC_BAD_ACCESS

    return 0;
}

When converting the result of the bind to jobFunctor there is an infinite stack recursion in a std::function constructor.

I am running Mac OS X 10.8.5, I compile this code with Xcode 5.0.2 using libc++, the compiler version:

LO50F-04-198BX:$ clang++ --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
1 Answers
Related