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 <nathanieloshead@gmail.com>
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))
--- /dev/null
+// { 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" }