On 4/6/20 9:05 PM, Marek Polacek wrote:
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 ().
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
PR c++/94507 - ICE-on-invalid with lambda template.
* pt.c (tsubst_lambda_expr): Cope when tsubst_template_decl returns
error_mark_node.
* g++.dg/cpp2a/lambda-generic7.C: New test.
---
gcc/cp/pt.c | 6 ++++++
gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++
2 files changed, 16 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 6122227c22f..f804ba18692 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18876,6 +18876,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);
}
Perhaps we also want an early exit if the tsubst_function_decl in the
else clause returns error_mark_node?
@@ -18948,6 +18953,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/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" }
+}
base-commit: 130f703da0c0d7b785d394b17df884379b4aadd9