This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53202] Copy constructor not called when starting a thread
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 03 May 2012 01:14:28 +0000
- Subject: [Bug c++/53202] Copy constructor not called when starting a thread
- Auto-submitted: auto-generated
- References: <bug-53202-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53202
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-03 01:14:28 UTC ---
If I change some of the functions to forward lvalues instead of using perfect
forwarding then I see one call to a copy constructor
e.g. just changing the thread::Impl ctor to
Impl(const T& t) : t(t) { }
produces:
default ctor called, this=0x7fffd878f35f
copy ctor called
destructor called, this=0x7fffd878f327
void background_hello::operator()() called, this=0x1258010
destructor called, this=0x1258010
destructor called, this=0x7fffd878f35f
The gimple dump shows:
thread::Impl<T>::Impl(const T&) [with T = Bind_simple<background_hello>]
(struct Impl * const this, const struct Bind_simple & t)
{
struct Bind_simple * D.8913;
struct Bind_simple * D.8914;
thread::ImplBase::ImplBase (this);
D.8913 = &this->t;
Bind_simple<background_hello>::Bind_simple (D.8913, t);
try
{
}
catch
{
D.8914 = &this->t;
Bind_simple<background_hello>::~Bind_simple (D.8914);
}
}
Note the copy construction of the Bind_simple member that was missing
previously