re PR c++/63320 (bogus ‘this’ was not captured for this lambda function error)
authorJason Merrill <jason@redhat.com>
Mon, 22 Sep 2014 19:22:11 +0000 (15:22 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 22 Sep 2014 19:22:11 +0000 (15:22 -0400)
PR c++/63320
PR c++/60463
PR c++/60755
* lambda.c (maybe_resolve_dummy, lambda_expr_this_capture): Handle
not finding 'this'.

From-SVN: r215478

gcc/cp/ChangeLog
gcc/cp/lambda.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-ice3.C
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C [new file with mode: 0644]

index 7d23a773ab1337a5a82b9b793bd5bccea644393b..f209e15794edfa5367c45b1a92c24543a6304b58 100644 (file)
@@ -1,3 +1,11 @@
+2014-09-22  Jason Merrill  <jason@redhat.com>
+
+       PR c++/63320
+       PR c++/60463
+       PR c++/60755
+       * lambda.c (maybe_resolve_dummy, lambda_expr_this_capture): Handle
+       not finding 'this'.
+
 2014-09-22  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/62219
index 0d8d4551a0f6aad6171ee5cc5b6d136390e4c170..17fd0377eb9cde7b977c48c1170944007b21d6aa 100644 (file)
@@ -724,7 +724,8 @@ lambda_expr_this_capture (tree lambda, bool add_capture_p)
 
   if (!this_capture)
     {
-      error ("%<this%> was not captured for this lambda function");
+      if (add_capture_p)
+       error ("%<this%> was not captured for this lambda function");
       result = error_mark_node;
     }
   else
@@ -768,8 +769,9 @@ maybe_resolve_dummy (tree object, bool add_capture_p)
       /* In a lambda, need to go through 'this' capture.  */
       tree lam = CLASSTYPE_LAMBDA_EXPR (current_class_type);
       tree cap = lambda_expr_this_capture (lam, add_capture_p);
-      object = build_x_indirect_ref (EXPR_LOCATION (object), cap,
-                                    RO_NULL, tf_warning_or_error);
+      if (cap != error_mark_node)
+       object = build_x_indirect_ref (EXPR_LOCATION (object), cap,
+                                      RO_NULL, tf_warning_or_error);
     }
 
   return object;
index 03a7a4bb60d0539ad13d23b9e8e98aae9f3591eb..9c76d34496de756ba70482b2d41f51df701cd4a3 100644 (file)
@@ -3,7 +3,7 @@
 
 class Klass
 {
-  unsigned int local;
+  unsigned int local;          // { dg-error "non-static" }
 public:
   bool dostuff();
 };
@@ -11,7 +11,7 @@ public:
 bool Klass::dostuff()
 {
   auto f = []() -> bool {
-    if (local & 1) { return true; } // { dg-error "not captured" }
+    if (local & 1) { return true; } // { dg-error "not captured|this location" }
     return false;
   };
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this19.C
new file mode 100644 (file)
index 0000000..c4c041f
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/63320
+// { dg-do compile { target c++11 } }
+
+class A {
+  static void addWindow();
+  static void activateWindow(void *);
+};
+void A::addWindow() {
+  int* action {};
+  [action] { activateWindow(action); };
+}