简体   繁体   English

使用std :: function w / std :: bind时的EXC_BAD_ACCESS

[英]EXC_BAD_ACCESS when using std::function w/ std::bind

After upgrading to XCode 5 using std::function with std::bind appears to be generating EXC_BAD_ACCESS exceptions. 使用带有std :: bind的std :: function升级到XCode 5后,似乎会生成EXC_BAD_ACCESS异常。 It looks as if the __base pointer inside the implementation of std::function ends up being null, resulting in the bad access, but I'm not clear on why that would be the case. 看起来std :: function实现中的__base指针最终为null,导致访问不良,但我不清楚为什么会出现这种情况。 Does anyone have an insight into either what I'm doing wrong? 有没有人能够洞察我做错了什么?

Here is sample code that illustrates the problem. 以下是说明问题的示例代码。

struct A
{
    void foo(bool b)
    {
        std::cout << b << std::endl;
    }

    void go()
    {
        // ok
        auto a = std::bind(&A::foo, this, std::placeholders::_1);
        a(true);

        // ok
        std::function<void(A*, bool)> b = std::bind(&A::foo, std::placeholders::_1, std::placeholders::_2);
        b(this, true);

        // ok
        std::function<void(A*, bool)> c = std::bind(&A::foo, this, std::placeholders::_2);
    c(this, true);

        // EXC_BAD_ACCESS
        std::function<void(bool)> f = std::bind(&A::foo, this, std::placeholders::_1);
        f(true);
    }
};
...
...

A a;
a.go();

It seems that this may be a bug that has been fixed. 看来这可能是一个已修复的错误。 I had a similar issue ( std::bind to a std::function crashes with Clang ) where the solution simply was to upgrade from XCode 5.0.1 to XCode 5.0.2. 我有一个类似的问题( std :: bind到std :: function与Clang崩溃 ),解决方案只是从XCode 5.0.1升级到XCode 5.0.2。

I tried your code and it seems to work fine with XCode 5.0.2 (have not tried with 5.0.1). 我尝试了你的代码,它似乎与XCode 5.0.2(没有尝试使用5.0.1)工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将std :: vector作为参数传递给函数时为EXC_BAD_ACCESS - EXC_BAD_ACCESS when passing std::vector as a parameter to a function EXC_BAD_ACCESS(code=1, address=0x0) 在将 std::map 作为参数传递给虚函数调用时发生 - EXC_BAD_ACCESS(code=1, address=0x0) occurs when passing a std::map as parameter to a virtual function call 为什么这样使用std :: transform会导致exc_bad_access - Why does this use of std::transform cause exc_bad_access 结构的std :: string成员的EXC_BAD_ACCESS错误 - EXC_BAD_ACCESS error for std::string member of a structure 在 C++ 中使用 std::vector 快速排序,EXC_BAD_ACCESS 代码 2 - Quicksort in C++ with std::vector, EXC_BAD_ACCESS code 2 在C ++静态方法中使用std :: vector后推时会抛出EXC_BAD_ACCESS - std::vector pushback throws EXC_BAD_ACCESS when used inside a C++ static method 使用VBO时EXC_BAD_ACCESS - EXC_BAD_ACCESS when using VBO 调用函数时,指向指针的指针将获得EXC_BAD_ACCESS - Pointer to pointer gets EXC_BAD_ACCESS when calling function EXC_BAD_ACCESS 仅在 function 内构建 object 时 - EXC_BAD_ACCESS only when building object inside function 意外破坏std :: vector的静态声明时EXC_BAD_ACCESS <double> - EXC_BAD_ACCESS upon unexpected destruction of static declaration of std::vector<double>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM