On Wed, Apr 08, 2020 at 08:55:08AM -0400, Jason Merrill via Gcc-patches wrote: > 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?
Can't hurt (but don't have a testcase for it). Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- 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. --- gcc/cp/pt.c | 11 +++++++++++ gcc/testsuite/g++.dg/cpp2a/lambda-generic7.C | 10 ++++++++++ 2 files changed, 21 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..b9cbdb36de7 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); } @@ -18883,6 +18888,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); } @@ -18948,6 +18958,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 -- Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA