This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/59768] New: [4.8 Regression] std::thread constructor not handling reference_wrapper correctly
- From: "Casey at Carter dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 11 Jan 2014 07:34:28 +0000
- Subject: [Bug libstdc++/59768] New: [4.8 Regression] std::thread constructor not handling reference_wrapper correctly
- Auto-submitted: auto-generated
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.