https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97536
Bug ID: 97536 Summary: [concepts] parser segfault for concept defined in function template Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hello at josephloser dot com Target Milestone: --- The code below causes a segfault when parsing a concept definition inside a function template. Note that concepts cannot be defined inside a function scope, so this should result in a useful diagnostic. Output of compiling the program with -std=c++2a: prog.cc: In function 'auto foo()': prog.cc:3:5: warning: C++20 concept definition syntax is 'concept <name> = <expr>' 3 | concept bar = true; | ^~~~~~~ prog.cc:3:13: internal compiler error: Segmentation fault 3 | concept bar = true; | ^~~ 0xc2e30f crash_signal ../../source/gcc/toplev.c:330 0x68c49c grokvardecl ../../source/gcc/cp/decl.c:10103 0x68c49c grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*, decl_context, int, tree_node**) ../../source/gcc/cp/decl.c:13691 0x6913c8 start_decl(cp_declarator const*, cp_decl_specifier_seq*, int, tree_node*, tree_node*, tree_node**) ../../source/gcc/cp/decl.c:5218 0x71cc3e cp_parser_init_declarator ../../source/gcc/cp/parser.c:20934 0x6fe49c cp_parser_simple_declaration ../../source/gcc/cp/parser.c:13876 0x7002ad cp_parser_declaration_statement ../../source/gcc/cp/parser.c:13316 0x700e97 cp_parser_statement ../../source/gcc/cp/parser.c:11562 0x701e6d cp_parser_statement_seq_opt ../../source/gcc/cp/parser.c:11928 0x701f20 cp_parser_compound_statement ../../source/gcc/cp/parser.c:11878 0x718d2a cp_parser_function_body ../../source/gcc/cp/parser.c:23236 0x718d2a cp_parser_ctor_initializer_opt_and_function_body ../../source/gcc/cp/parser.c:23287 0x71c730 cp_parser_function_definition_after_declarator ../../source/gcc/cp/parser.c:29182 0x71d64f cp_parser_function_definition_from_specifiers_and_declarator ../../source/gcc/cp/parser.c:29098 0x71d64f cp_parser_init_declarator ../../source/gcc/cp/parser.c:20838 0x722c14 cp_parser_single_declaration ../../source/gcc/cp/parser.c:29669 0x722d77 cp_parser_template_declaration_after_parameters ../../source/gcc/cp/parser.c:29242 0x72337a cp_parser_explicit_template_declaration ../../source/gcc/cp/parser.c:29507 0x726cd9 cp_parser_declaration ../../source/gcc/cp/parser.c:13524 0x72726d cp_parser_translation_unit ../../source/gcc/cp/parser.c:4793 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. Wandbox link: https://wandbox.org/permlink/PKqzkXQLl3fv8ev4 For what its worth, the warning given for when a concept is defined inside a function (not a function template) could probably be improved as well. If you remove the template on `foo` such that it is just a function, the error is: prog.cc: In function 'auto foo()': prog.cc:2:5: warning: C++20 concept definition syntax is 'concept <name> = <expr>' 2 | concept bar = true; | ^~~~~~~ prog.cc:2:5: error: a non-template variable cannot be 'concept' The error message is fine, but the warning is a bit of a misnomer as `concept bar = true;` does meet the grammar of `concept <name> = <expr>`.