Commit 78a2ea41 by Jason Merrill Committed by Jason Merrill

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
parent 70cc3288
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> 2013-02-13 Jakub Jelinek <jakub@redhat.com>
PR c++/56302 PR c++/56302
......
...@@ -14457,9 +14457,11 @@ tsubst_copy_and_build (tree t, ...@@ -14457,9 +14457,11 @@ tsubst_copy_and_build (tree t,
complete_type (type); complete_type (type);
/* The capture list refers to closure members, so this needs to /* 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) 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; LAMBDA_EXPR_THIS_CAPTURE (r) = NULL_TREE;
RETURN (build_lambda_object (r)); RETURN (build_lambda_object (r));
......
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment