This fixes a crash on invalid requires-expression: in this test,
current_template_parms is null so accessing TEMPLATE_PARMS_CONSTRAINTS
is going to fail. So don't crash, but make sure we've complained
already.
gcc/cp/ChangeLog:
PR c++/100055
* decl.c (grokfndecl): Check current_template_parms.
gcc/testsuite/ChangeLog:
PR c++/100055
* g++.dg/concepts/diagnostic18.C: New test.
&& (processing_template_decl
> template_class_depth (ctx)));
if (memtmpl)
- tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
+ {
+ if (!current_template_parms)
+ /* If there are no template parameters, something must have
+ gone wrong. */
+ gcc_assert (seen_error ());
+ else
+ tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
+ }
tree ci = build_constraints (tmpl_reqs, decl_reqs);
if (concept_p && ci)
{
--- /dev/null
+// PR c++/100055
+// { dg-do compile { target concepts } }
+
+void foo(auto&& arg) requires({}); // { dg-error "statement-expressions are not allowed|braced-groups" }
+
+template <auto = 0> requires ([]{}()); // { dg-error "expected unqualified-id" }
+auto f() requires ([]{}());