0

msvc-11.0 中的 std::thread 实现似乎有忽略调用约定的问题。

我有以下程序:

主文件

 # include <stdio.h>
 # include <thread>

 class foo
 {
 public:
    //intentional __stdcall, breaks compilation
    virtual void __stdcall printOut(const char* str)
    {
       printf("%s", str);
    }
 };

 foo bar;

 int main(void)
 {
    std::thread(&foo::printOut, &bar, "Printing output");
    return 0;
 }

尝试使用 msvc 11.0 (VS2012) 编译上述代码会引发以下错误:

error C2064: term does not evaluate to a function taking 2 arguments
        ...\functional(1152) : while compiling class template member function 'std::_Do_call_ret<_Forced,_Ret,_Funx,_Btuple,_Ftuple>::type std::_Bind<false,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>::operator ()(void)'
        with
        [
            _Forced=false,
            _Ret=void,
            _Funx=void (__stdcall foo::* )(const char *),
            _Btuple=std::tuple<foo *,const char *>,
            _Ftuple=std::tuple<>,
            _Fun=void (__stdcall foo::* )(const char *),
            _V0_t=foo *,
            _V1_t=const char (&)[13],
            _V2_t=std::_Nil,
            _V3_t=std::_Nil,
            _V4_t=std::_Nil,
            _V5_t=std::_Nil,
            <unnamed-symbol>=std::_Nil
        ]
        .../xthread(195) : see reference to function template instantiation 'std::_Do_call_ret<_Forced,_Ret,_Funx,_Btuple,_Ftuple>::type std::_Bind<false,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>::operator ()(void)' being compiled
        with
        [
            _Forced=false,
            _Ret=void,
            _Funx=void (__stdcall foo::* )(const char *),
            _Btuple=std::tuple<foo *,const char *>,
            _Ftuple=std::tuple<>,
            _Fun=void (__stdcall foo::* )(const char *),
            _V0_t=foo *,
            _V1_t=const char (&)[13],
            _V2_t=std::_Nil,
            _V3_t=std::_Nil,
            _V4_t=std::_Nil,
            _V5_t=std::_Nil,
            <unnamed-symbol>=std::_Nil
        ]
       ...\thread(52) : see reference to class template instantiation 'std::_Bind<_Forced,_Ret,_Fun,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,<unnamed-symbol>>' being compiled
        with
        [
            _Forced=false,
            _Ret=void,
            _Fun=void (__stdcall foo::* )(const char *),
            _V0_t=foo *,
            _V1_t=const char (&)[13],
            _V2_t=std::_Nil,
            _V3_t=std::_Nil,
            _V4_t=std::_Nil,
            _V5_t=std::_Nil,
            <unnamed-symbol>=std::_Nil
        ]
        main.cpp(24) : see reference to function template instantiation 'std::thread::thread<void(__stdcall foo::* )(const char *),foo*,const char(&)[13]>(_Fn,_V0_t &&,_V1_t)' being compiled
        with
        [
            _Fn=void (__stdcall foo::* )(const char *),
            _V0_t=foo *,
            _V1_t=const char (&)[13]
        ]

如果没有 __stdcall,这个程序可以正常构建。是否有调用约定 IMO 对 std::thread 无关紧要,但它似乎会影响解释此方法的方式。编译器似乎很难看到printOut(const char*)符合定义 - (foo::* )(const char *)

这是 msvc 11.0 的问题还是我在这里遗漏了什么?

4

0 回答 0