https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78896
Bug ID: 78896 Summary: Segmentation fault occurs when use variable initialized using structured binding with capture-by-ref lambda Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: duongdominhchau at hotmail dot com Target Milestone: --- I found a segmentation fault while trying structured binding using GCC 7: This is the source code which caused the segmentation fault: int main() { int a {10}; auto [b]{ [&a](){} }; return b - a; } The same code under Clang 4 would raise an error instead of a segmentation fault. GCC 7: http://melpon.org/wandbox/permlink/WDd8mSy4dCXj8CSa Clang 4: http://melpon.org/wandbox/permlink/EQfQxrdTrbNbTw2b If I change the lambda to capture by value, or never use the variable initialized using structured binding (the variable `b` in my code), no segmentation fault occurs. This is the output of the compiler: prog.cc: In function 'int main()': prog.cc:4:10: internal compiler error: Segmentation fault return b - a; ^ 0xb04b0f crash_signal /home/heads/gcc/gcc-source/gcc/toplev.c:333 0x88b893 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, expand_modifier, rtx_def**, bool) /home/heads/gcc/gcc-source/gcc/expr.c:10107 0x895c1a store_expr_with_bounds(tree_node*, rtx_def*, int, bool, bool, tree_node*) /home/heads/gcc/gcc-source/gcc/expr.c:5552 0x89684e expand_assignment(tree_node*, tree_node*, bool) /home/heads/gcc/gcc-source/gcc/expr.c:5321 0x7ab45d expand_gimple_stmt_1 /home/heads/gcc/gcc-source/gcc/cfgexpand.c:3641 0x7ab45d expand_gimple_stmt /home/heads/gcc/gcc-source/gcc/cfgexpand.c:3737 0x7aca1f expand_gimple_basic_block /home/heads/gcc/gcc-source/gcc/cfgexpand.c:5744 0x7b1be6 execute /home/heads/gcc/gcc-source/gcc/cfgexpand.c:6355 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.