]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/56135 ([c++11] this incorrectly captured as null in template member function)
authorJason Merrill <jason@redhat.com>
Fri, 15 Feb 2013 18:31:28 +0000 (13:31 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 15 Feb 2013 18:31:28 +0000 (13:31 -0500)
PR c++/56135
* pt.c (tsubst_copy_and_build): Don't forget any new
captures that arose from use of dependent names.

From-SVN: r196085

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

index de88e1161c2827d946031b73d2bbf42ab160acac..bd1d17ef2c9bf2fa469e01b82233dd5e12f1f2a8 100644 (file)
@@ -1,3 +1,9 @@
+2013-02-15  Jason Merrill  <jason@redhat.com>
+
+       PR c++/56135
+       * pt.c (tsubst_copy_and_build): Don't forget any new
+       captures that arose from use of dependent names.
+
 2013-02-12  Jason Merrill  <jason@redhat.com>
 
        PR c++/56291
index db63377c31660ffbae9c2dbe93bfb32deac79d58..97305d2bffecde7d70f31f72c508d252236fe92e 100644 (file)
@@ -14116,9 +14116,11 @@ tsubst_copy_and_build (tree t,
        complete_type (type);
 
        /* The capture list refers to closure members, so this needs to
-          wait until after we finish instantiating the type.  */
+          wait until after we finish instantiating the type.  Also keep
+          any captures that may have been added during instantiation.  */
        LAMBDA_EXPR_CAPTURE_LIST (r)
-         = RECUR (LAMBDA_EXPR_CAPTURE_LIST (t));
+         = chainon (RECUR (LAMBDA_EXPR_CAPTURE_LIST (t)),
+                    LAMBDA_EXPR_CAPTURE_LIST (r));
        LAMBDA_EXPR_THIS_CAPTURE (r) = NULL_TREE;
 
        return build_lambda_object (r);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this8.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this8.C
new file mode 100644 (file)
index 0000000..d7c5d2c
--- /dev/null
@@ -0,0 +1,37 @@
+// PR c++/56135
+// { dg-do run { target c++11 } }
+
+#include <functional>
+
+struct test {
+  template<typename T>
+  std::function<void()> broken(int x) {
+    return [=] { +x; print<T>(); };
+  }
+
+  std::function<void()> works0() {
+    return [=] { print<int>(); };
+  }
+
+  template<typename T>
+  std::function<void()> works1() {
+    return [=] { print<int>(); };
+  }
+
+  template<typename T>
+  std::function<void()> works2() {
+    return [=] { this->print<T>(); };
+  }
+
+  template<typename T>
+  void print() { if (this == 0) __builtin_abort (); }
+};
+
+int main(void) {
+  test().broken<int>(1)();
+  test().works0()();
+  test().works1<int>()();
+  test().works2<int>()();
+
+  return 0;
+}