https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67436
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |ice-on-valid-code Status|UNCONFIRMED |NEW Last reconfirmed| |2015-09-02 Ever confirmed|0 |1 Known to fail| |6.0 --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Johannes S. Mueller-Roemer from comment #0) > I encountered an error with a missing __tls_init after using a thread_local > variable within a generic lambda. I was able to work around this bug by > creating a reference to the thread_local and using the reference in the > lambda instead. That sounds similar to an example discussed by the committee recently: void f() { thread_local int n = 10; std::thread([&] { std::cout << n << std::endl; }).join(); } The reference to n inside the lambda is to the variable in the new thread, which was never initialized because the flow of control never reached its initializer. This is probably a defect in the standard. > I was not able to reproduce the exact same behavior with a minimal example, > however this code > > int main(int, char**) > { > thread_local int foo; > [&] (auto bar) { > foo += bar; > }(1u); > return 0; > } > > Causes an internal compiler error Confirmed, also ICEs on trunk.