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.carl...@oracle.com>

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

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

        PR c++/71570
        * g++.dg/cpp0x/lambda/lambda-ice17.C: New.
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);
+  };
+}

Reply via email to