https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79488
Bug ID: 79488 Summary: [7 Regression] ICE from lambda that has invalid return type Product: gcc Version: 7.0.1 Status: UNCONFIRMED Keywords: ice-on-invalid-code Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- This is reduced from Bug 79486, where a bug in the libstdc++ code could trigger this ICE. Without the weakref or the 'virtual' keyword there's no ICE. int f(); static int g __attribute__((__weakref__("f"))); template <typename Fn> struct res { static Fn val(); using type = decltype(val()()); }; template <typename Fn> struct A { template <typename T> void set_result(T) {} virtual void run() { auto boundfn = []() -> typename res<Fn>::type{}; set_result(boundfn); } }; struct F { void operator()() &; }; A<F> t; r.cc: In instantiation of 'struct res<F>': r.cc:13:46: required from 'struct A<Fn>::run() [with Fn = F]::<lambda>' r.cc:13:10: required from 'void A<Fn>::run() [with Fn = F]' r.cc:22:7: required from here r.cc:6:30: error: no match for call to '(F) ()' using type = decltype(val()()); ~~~~~^~ r.cc:19:8: note: candidate: void F::operator()() & <near match> void operator()() &; ^~~~~~~~ r.cc:19:8: note: passing 'F' as 'this' argument discards qualifiers r.cc:10:30: error: 'void A<Fn>::set_result(T) [with T = A<Fn>::run() [with Fn = F]::<lambda>; Fn = F]', declared using local type 'A<Fn>::run() [with Fn = F]::<lambda>', is used but never defined [-fpermissive] template <typename T> void set_result(T) {} ^~~~~~~~~~ r.cc: In instantiation of 'void A<Fn>::set_result(T) [with T = A<Fn>::run() [with Fn = F]::<lambda>; Fn = F]': r.cc:12:16: required from here r.cc:10:30: internal compiler error: Segmentation fault 0xdbb6df crash_signal /home/jwakely/src/gcc/gcc/gcc/toplev.c:337 0x845d56 contains_struct_check(tree_node*, tree_node_structure_enum, char const*, int, char const*) /home/jwakely/src/gcc/gcc/gcc/tree.h:3177 0x845d56 write_closure_type_name /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:1639 0x845d56 write_unqualified_name /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:1383 0x84bab7 write_name /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:937 0x84b95c write_local_name /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:2035 0x84b95c write_name /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:964 0x84c5a9 write_class_enum_type /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:2777 0x84c5a9 write_type /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:2195 0x84b488 write_template_args /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:2806 0x851bad write_nested_name /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:1063 0x84b7f7 write_name /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:976 0x850476 write_encoding /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:825 0x8524fc mangle_decl_string /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:3757 0x85274b get_mangled_id /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:3779 0x85274b mangle_decl(tree_node*) /home/jwakely/src/gcc/gcc/gcc/cp/mangle.c:3849 0x1063490 decl_assembler_name(tree_node*) /home/jwakely/src/gcc/gcc/gcc/tree.c:671 0x9a836c symbol_table::insert_to_assembler_name_hash(symtab_node*, bool) /home/jwakely/src/gcc/gcc/gcc/symtab.c:171 0x9ae38f cgraph_node::create(tree_node*) /home/jwakely/src/gcc/gcc/gcc/cgraph.c:511 0x9ae1e0 cgraph_node::get_create(tree_node*) /home/jwakely/src/gcc/gcc/gcc/cgraph.c:533 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions.