http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59768
Bug ID: 59768 Summary: [4.8 Regression] std::thread constructor not handling reference_wrapper correctly Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: Casey at Carter dot net Created attachment 31809 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31809&action=edit Minimal test case. Originally reported in Stackoverflow question http://stackoverflow.com/questions/21059115/c11-thread-class-how-to-use-a-class-member-function Construction of a std::thread with a pointer-to-member-function and reference_wrapper as in this simple program: #include <functional> #include <iostream> #include <thread> class A { public: void foo(int n) { std::cout << n << std::endl; } }; int main() { A a; std::thread t1(&A::foo, std::ref(a), 100); t1.join(); } incorrectly results in a compilation error: In file included from /usr/local/include/c++/4.8.2/thread:39:0, from check.cc:2: /usr/local/include/c++/4.8.2/functional: In instantiation of ‘struct std::_Bind_simple<std::_Mem_fn<void (A::*)(int)>(std::reference_wrapper<A>, int)>’: /usr/local/include/c++/4.8.2/thread:137:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (A::*)(int); _Args = {std::reference_wrapper<A>, int}]’ check.cc:13:42: required from here /usr/local/include/c++/4.8.2/functional:1697:61: error:no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void (A::*)(int)>(std::reference_wrapper<A>, int)>’ typedef typename result_of<_Callable(_Args...)>::type result_type; ^ /usr/local/include/c++/4.8.2/functional:1727:9: error:no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void (A::*)(int)>(std::reference_wrapper<A>, int)>’ _M_invoke(_Index_tuple<_Indices...>) ^ I reduced the original program to: #include <functional> #include <thread> int main() { struct A { void foo(int) {} } a; std::thread(&A::foo, std::ref(a), 100).join(); } which still displays the erroneous behavior. Note that std::bind(&A::foo, std::ref(a), 100) *does* compile correctly, as does a similar program in which the member function foo has no parameter. Program is incorrectly compiled by g++ 4.8.2 and 4.8.1, correctly compiles with 4.6.4 and 4.7.3.