https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69774
Bug ID: 69774 Summary: Corrupted 'this' passed through lambda. Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: guille at cal dot berkeley.edu Target Milestone: --- Created attachment 37669 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37669&action=edit Preprocessed source The code below compiles+runs fine on gcc 4.7, but fails on gcc version 6.0.0 20151220 (on intel Mac). On gcc 4.7 it outputs the same two pointers (say "0x7fff5f896ba0 0x7fff5f896ba0"), while on 6.0.0 it outputs "0x7fff5f896ba0 0x7fff5f896bc0"). #include <thread> #include <iostream> struct Thread : std::thread { Thread() = default; template <class F, class... P> Thread(F&& task, P&&... p) : std::thread( [&task] (P&&... p) { task(std::forward<P> (p)...); }, std::forward<P> (p)... ) {} Thread& operator = (Thread&& t) { (std::thread&)*this = std::move((std::thread&)t); return *this; } }; struct A { int a; Thread t; A() { t = [this] { std::cerr << &a << " \n"; }; } ~A() { t.join(); } }; int main() { A a; std::cerr << &a.a << " \n"; return 0; }