public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix ICE-on-invalid with lambda template [PR94507]
@ 2020-04-07  1:05 Marek Polacek
  2020-04-08 12:55 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2020-04-07  1:05 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

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);
 	}
@@ -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
-- 
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-08 17:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07  1:05 [PATCH] c++: Fix ICE-on-invalid with lambda template [PR94507] Marek Polacek
2020-04-08 12:55 ` Jason Merrill
2020-04-08 13:44   ` [PATCH v2] " Marek Polacek
2020-04-08 17:35     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).