diff mbox

[C++] PR 71570 ("[6/7/8 regression] ICE on invalid variable capture in cxx_incomplete_type_diagnostic...")

Message ID 56593f23-748c-fd5f-9cad-0ba3fc4118ce@oracle.com
State New
Headers show

Commit Message

Paolo Carlini July 26, 2017, 6:49 p.m. UTC
Hi,

avoiding the error recovery issues noticed in the bug seems just matter 
of early returning error_mark_node from add_capture, like we already do 
a few lines below in a similar case of ill-formed capture. Tested 
x86_64-linux. If we are going to fix this in a simply way, maybe we 
could also backport to 7...

Thanks, Paolo.

////////////////////
/cp
2017-07-26  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/71570
	* lambda.c (add_capture): Early return if we cannot capture by
	reference.

/testsuite
2017-07-26  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/71570
	* g++.dg/cpp0x/lambda/lambda-ice17.C: New.

Comments

Jason Merrill July 26, 2017, 7:43 p.m. UTC | #1
OK; this is trivial enough for 6/7/8.

On Wed, Jul 26, 2017 at 2:49 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> Hi,
>
> avoiding the error recovery issues noticed in the bug seems just matter of
> early returning error_mark_node from add_capture, like we already do a few
> lines below in a similar case of ill-formed capture. Tested x86_64-linux. If
> we are going to fix this in a simply way, maybe we could also backport to
> 7...
>
> Thanks, Paolo.
>
> ////////////////////
>
diff mbox

Patch

Index: cp/lambda.c
===================================================================
--- cp/lambda.c	(revision 250586)
+++ cp/lambda.c	(working copy)
@@ -529,7 +529,10 @@  add_capture (tree lambda, tree id, tree orig_init,
       else if (id != this_identifier && by_reference_p)
 	{
 	  if (!lvalue_p (initializer))
-	    error ("cannot capture %qE by reference", initializer);
+	    {
+	      error ("cannot capture %qE by reference", initializer);
+	      return error_mark_node;
+	    }
 	}
       else
 	{
Index: testsuite/g++.dg/cpp0x/lambda/lambda-ice17.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-ice17.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-ice17.C	(working copy)
@@ -0,0 +1,12 @@ 
+// PR c++/71570
+// { dg-do compile { target c++11 } }
+
+void foo (int);
+
+void foo (void)
+{
+  [&foo] // { dg-error "cannot capture" }
+  {
+    foo (0);
+  };
+}