From: Nathaniel Shead Date: Fri, 12 Sep 2025 13:26:20 +0000 (+1000) Subject: c++: Fix error recovery after export keyword [PR121832] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff7d7898bb40d4bc72ad157d48eaa42fbe022512;p=thirdparty%2Fgcc.git c++: Fix error recovery after export keyword [PR121832] When we enter cp_parser_explicit_template_declaration with the following tokens being 'template <>', we never parse a parameter list and so with -fconcepts we crash dereferencing a null pointer. This can currently only happen after a non-modules 'export' declaration, as all other paths check early for this case. PR c++/121832 gcc/cp/ChangeLog: * parser.cc (cp_parser_explicit_template_declaration): Check for null. gcc/testsuite/ChangeLog: * g++.dg/concepts/pr121832.C: New test. Signed-off-by: Nathaniel Shead --- diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 392d1f90ac8..4d988c27cb8 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -36275,7 +36275,7 @@ cp_parser_explicit_template_declaration (cp_parser* parser, bool member_p) cp_parser_require_end_of_template_parameter_list (parser); /* Manage template requirements */ - if (flag_concepts) + if (flag_concepts && current_template_parms) { tree reqs = get_shorthand_constraints (current_template_parms); if (tree treqs = cp_parser_requires_clause_opt (parser, false)) diff --git a/gcc/testsuite/g++.dg/concepts/pr121832.C b/gcc/testsuite/g++.dg/concepts/pr121832.C new file mode 100644 index 00000000000..9a4c5c045d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/pr121832.C @@ -0,0 +1,10 @@ +// { dg-do compile } +// { dg-additional-options "-fconcepts -fno-modules" } + +export template<> a{}; // { dg-error "explicit spec" } +// { dg-warning "'export' not implemented" "" { target c++98_only } .-1 } +// { dg-warning "'export' is deprecated" "" { target { c++11 && c++17_down } } .-2 } +// { dg-warning "'export' is enabled with '-fmodules'" "" { target c++20 } .-3 } + +// { dg-prune-output "'a' does not name a type" } +// { dg-prune-output "extra ';' outside of a function" }