aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2013-02-13 12:56:05 -0500
committerJason Merrill <jason@gcc.gnu.org>2013-02-13 12:56:05 -0500
commit78a2ea4199b0292a4fada84baa2db53f6b67e0f0 (patch)
tree6757bf0aacf35f9eab5e3c69821c4770fcc2e684 /gcc
parent70cc32885899d283acc811b075c4e6aa8199e173 (diff)
downloadgcc-78a2ea4199b0292a4fada84baa2db53f6b67e0f0.zip
gcc-78a2ea4199b0292a4fada84baa2db53f6b67e0f0.tar.gz
gcc-78a2ea4199b0292a4fada84baa2db53f6b67e0f0.tar.bz2
re PR c++/56135 ([c++11] this incorrectly captured as null in template member function)
PR c++/56135 * pt.c (tsubst_copy_and_build): Don't forget any new captures that arose from use of dependent names. From-SVN: r196021
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this8.C39
3 files changed, 49 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 442b369..e3b927b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2013-02-13 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-13 Jakub Jelinek <jakub@redhat.com>
PR c++/56302
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a3359ad..2aadd4d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14457,9 +14457,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
index 0000000..9309a44
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this8.C
@@ -0,0 +1,39 @@
+// PR c++/56135
+// { dg-do run { target c++11 } }
+
+#include <functional>
+
+extern "C" void abort() throw();
+
+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 == NULL) abort (); }
+};
+
+int main(void) {
+ test().broken<int>(1)();
+ test().works0()();
+ test().works1<int>()();
+ test().works2<int>()();
+
+ return 0;
+}