diff options
author | Marek Polacek <polacek@redhat.com> | 2021-04-22 17:32:01 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2021-05-03 12:39:43 -0400 |
commit | c9b6890d0b6aa030b307fdb620f8c53ed59ca3b5 (patch) | |
tree | 92f1c916e30e79d3b0fce9a5d9b2fcf246578f26 | |
parent | 6252e35cf5cea9a30a57ceffbc7a9f3160900a45 (diff) | |
download | gcc-c9b6890d0b6aa030b307fdb620f8c53ed59ca3b5.zip gcc-c9b6890d0b6aa030b307fdb620f8c53ed59ca3b5.tar.gz gcc-c9b6890d0b6aa030b307fdb620f8c53ed59ca3b5.tar.bz2 |
c++: Fix ICE with invalid requires-expression [PR100055]
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.
-rw-r--r-- | gcc/cp/decl.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/concepts/diagnostic18.C | 7 |
2 files changed, 15 insertions, 1 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d1e7337..316ad4c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9737,7 +9737,14 @@ grokfndecl (tree ctype, && (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) { diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic18.C b/gcc/testsuite/g++.dg/concepts/diagnostic18.C new file mode 100644 index 0000000..79f371b --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/diagnostic18.C @@ -0,0 +1,7 @@ +// 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 ([]{}()); |