From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EA5AD3857C5B; Fri, 23 Oct 2020 01:14:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA5AD3857C5B From: "hello at josephloser dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97536] New: [concepts] parser segfault for concept defined in function template Date: Fri, 23 Oct 2020 01:14:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hello at josephloser dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Oct 2020 01:14:46 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97536 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=3Dc++2a: prog.cc: In function 'auto foo()': prog.cc:3:5: warning: C++20 concept definition syntax is 'concept =3D ' 3 | concept bar =3D true; | ^~~~~~~ prog.cc:3:13: internal compiler error: Segmentation fault 3 | concept bar =3D 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 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 y= ou 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 =3D ' 2 | concept bar =3D 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 `conce= pt bar =3D true;` does meet the grammar of `concept =3D `.=