[gcc/devel/ranger] c++: Fix ICE-on-invalid with lambda template [PR94507]
Aldy Hernandez
aldyh@gcc.gnu.org
Wed Jun 17 20:18:10 GMT 2020
https://gcc.gnu.org/g:77d6dfc929832a542a25fc455b90f1a4bc83229c
commit 77d6dfc929832a542a25fc455b90f1a4bc83229c
Author: Marek Polacek <polacek@redhat.com>
Date: Mon Apr 6 19:59:04 2020 -0400
c++: Fix ICE-on-invalid with lambda template [PR94507]
While reducing something else I noticed that we ICE on the following
invalid code. In tsubst_lambda_expr, tsubst_template_decl has already
reported an error and returned the error_mark_node, so make sure we
don't ICE on that. I'm using a goto here because we still have to
do finish_struct because it does popclass ().
PR c++/94507 - ICE-on-invalid with lambda template.
* pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl or
tsubst_function_decl returns error_mark_node.
* g++.dg/cpp2a/lambda-generic7.C: New test.
Diff:
---
gcc/cp/ChangeLog | 6 ++++++
gcc/cp/pt.c | 11 +++++++++++
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++
4 files changed, 32 insertions(+)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7c5edc266d6..50f1857a3ec 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-08 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94507 - ICE-on-invalid with lambda template.
+ * pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl or
+ tsubst_function_decl returns error_mark_node.
+
2020-04-08 Martin Liska <mliska@suse.cz>
PR c++/94314
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 256a937eace..050a57b2e2e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18953,6 +18953,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (oldtmpl)
{
tmpl = tsubst_template_decl (oldtmpl, args, complain, fntype);
+ if (tmpl == error_mark_node)
+ {
+ r = error_mark_node;
+ goto out;
+ }
fn = DECL_TEMPLATE_RESULT (tmpl);
finish_member_declaration (tmpl);
}
@@ -18960,6 +18965,11 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
{
tmpl = NULL_TREE;
fn = tsubst_function_decl (oldfn, args, complain, fntype);
+ if (fn == error_mark_node)
+ {
+ r = error_mark_node;
+ goto out;
+ }
finish_member_declaration (fn);
}
@@ -19025,6 +19035,7 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
maybe_add_lambda_conv_op (type);
}
+out:
finish_struct (type, /*attr*/NULL_TREE);
insert_pending_capture_proxies ();
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index db4f6392493..6ed51141ac2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-08 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94507 - ICE-on-invalid with lambda template.
+ * g++.dg/cpp2a/lambda-generic7.C: New test.
+
2020-04-08 Alexandre Oliva <oliva@adacore.com>
* gcc.target/arm/fp16-aapcs-3.c: Explicitly use the
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
new file mode 100644
index 00000000000..bedba683671
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
@@ -0,0 +1,10 @@
+// PR c++/94507 - ICE-on-invalid with lambda template.
+// { dg-do compile { target c++2a } }
+
+struct S { };
+
+template<typename T, typename U>
+auto foo(T, U)
+{
+ [] <> () { foo (S{}, S{}); }; // { dg-error "expected" }
+}
More information about the Gcc-cvs
mailing list