https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125457
Bug ID: 125457
Summary: ICE when using modules with templates
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: d7d1cd at mail dot ru
Target Milestone: ---
Create two modules and a file with the main function:
$ cat foo.ixx
export module foo;
template <typename T>
struct Foo {};
export using FooInst = Foo<int>;
$ cat bar.ixx
export module bar;
import foo;
export struct Bar { FooInst f; };
$ cat main.cc
import bar;
int main() { Bar b; }
Try compiling this into a program and you'll get ICE:
$ g++ -std=c++23 -fmodules foo.ixx bar.ixx main.cc
main.cc: In function ‘int main()’:
main.cc:3:18: internal compiler error: Segmentation fault
3 | int main() { Bar b; }
| ^
0x2388cff internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:787
0x10a1cbf crash_signal
../../gcc/toplev.cc:325
0x7db83f vec<tree_node*, va_gc, vl_embed>::iterate(unsigned int,
tree_node**) const
../../gcc/vec.h:960
0x7db83f is_really_empty_class(tree_node*, bool)
../../gcc/cp/class.cc:9511
0x7db8e0 is_really_empty_class(tree_node*, bool)
../../gcc/cp/class.cc:9519
0x86a992 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
../../gcc/cp/decl.cc:9713
0x974017 cp_parser_init_declarator
../../gcc/cp/parser.cc:26415
0x9761ba cp_parser_simple_declaration
../../gcc/cp/parser.cc:18099
0x9796de cp_parser_declaration_statement
../../gcc/cp/parser.cc:16955
0x93ce46 cp_parser_statement
../../gcc/cp/parser.cc:14462
0x9411e0 cp_parser_statement_seq_opt
../../gcc/cp/parser.cc:15032
0x94147f cp_parser_compound_statement
../../gcc/cp/parser.cc:14879
0x9797e4 cp_parser_function_body
../../gcc/cp/parser.cc:28880
0x9797e4 cp_parser_ctor_initializer_opt_and_function_body
../../gcc/cp/parser.cc:28931
0x9419a5 cp_parser_function_definition_after_declarator
../../gcc/cp/parser.cc:36154
0x974dfa cp_parser_function_definition_from_specifiers_and_declarator
../../gcc/cp/parser.cc:36069
0x974dfa cp_parser_init_declarator
../../gcc/cp/parser.cc:26079
0x9761ba cp_parser_simple_declaration
../../gcc/cp/parser.cc:18099
0x981eeb cp_parser_declaration
../../gcc/cp/parser.cc:17636
0x984b1f cp_parser_toplevel_declaration
../../gcc/cp/parser.cc:17740
Here's an example on godbolt: https://godbolt.org/z/E5dbo4a9r