https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67436
Bug ID: 67436 Summary: [C++14] Generic lambda capture fails for thread_local variables Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: critical Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: j.s.mueller-roemer at gmx dot net Target Milestone: --- 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. 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 tls_init_bug.cpp: In instantiation of ‘main(int, char**)::<lambda(auto:1)> [with auto:1 = unsigned int]’: tls_init_bug.cpp:6:6: required from here tls_init_bug.cpp:1:5: internal compiler error: in tsubst_decl, at cp/pt.c:10836 int main(int, char**) ^ 0x658caa tsubst_decl ../../gcc-5.2.0/gcc/cp/pt.c:10836 0x64b084 tsubst(tree_node*, tree_node*, int, tree_node*) ../../gcc-5.2.0/gcc/cp/pt.c:11934 0x656ba2 tsubst_copy ../../gcc-5.2.0/gcc/cp/pt.c:13093 0x647c18 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc-5.2.0/gcc/cp/pt.c:15705 0x648e53 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc-5.2.0/gcc/cp/pt.c:15032 0x650162 tsubst_expr ../../gcc-5.2.0/gcc/cp/pt.c:14530 0x64f2c6 tsubst_expr ../../gcc-5.2.0/gcc/cp/pt.c:13941 0x6500ac tsubst_expr ../../gcc-5.2.0/gcc/cp/pt.c:14113 0x6500ac tsubst_expr ../../gcc-5.2.0/gcc/cp/pt.c:14113 0x64ee17 instantiate_decl(tree_node*, int, bool) ../../gcc-5.2.0/gcc/cp/pt.c:20543 0x67e062 mark_used(tree_node*, int) ../../gcc-5.2.0/gcc/cp/decl2.c:5032 0x61db00 build_over_call ../../gcc-5.2.0/gcc/cp/call.c:7501 0x620231 build_op_call_1 ../../gcc-5.2.0/gcc/cp/call.c:4345 0x620231 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) ../../gcc-5.2.0/gcc/cp/call.c:4368 0x6e7408 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int) ../../gcc-5.2.0/gcc/cp/semantics.c:2426 0x69b6e1 cp_parser_postfix_expression ../../gcc-5.2.0/gcc/cp/parser.c:6375 0x69db79 cp_parser_unary_expression ../../gcc-5.2.0/gcc/cp/parser.c:7438 0x69e6f7 cp_parser_binary_expression ../../gcc-5.2.0/gcc/cp/parser.c:8172 0x69eced cp_parser_assignment_expression ../../gcc-5.2.0/gcc/cp/parser.c:8430 0x6a1061 cp_parser_expression ../../gcc-5.2.0/gcc/cp/parser.c:8584 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. I originally found this error with GCC 5.1 mingw-w64, however it occurs with GCC 5.2 on linux as well.