* Re: C++ PATCH for c++/56135 (wrong 'this' capture)
@ 2013-02-14 11:59 Dominique Dhumieres
0 siblings, 0 replies; 2+ messages in thread
From: Dominique Dhumieres @ 2013-02-14 11:59 UTC (permalink / raw)
To: gcc-patches; +Cc: jason
Hi jason,
The test g++.dg/cpp0x/lambda/lambda-this8.C fails on x86_64-apple-darwin10:
FAIL: g++.dg/cpp0x/lambda/lambda-this8.C -std=c++11 (test for excess errors)
Excess errors:
/opt/gcc/work/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this8.C:6:31: error: declaration of 'void abort() throw ()' has a different exception specifier
/usr/include/stdlib.h:145:7: error: from previous declaration 'void abort()'
UNRESOLVED: g++.dg/cpp0x/lambda/lambda-this8.C -std=c++11 compilation failed to produce executable
TIA
Dominique
^ permalink raw reply [flat|nested] 2+ messages in thread
* C++ PATCH for c++/56135 (wrong 'this' capture)
@ 2013-02-13 14:21 Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2013-02-13 14:21 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 265 bytes --]
When the only use of 'this' is implicitly by a dependent name, we don't
see the capture until instantiation time. Don't clobber its capture
list entry when we instantiate the ones seen at template definition time.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 56135.patch --]
[-- Type: text/x-patch, Size: 1944 bytes --]
commit cdcb44a750af3921d6883832892dd8cd5e2d22b4
Author: Jason Merrill <jason@redhat.com>
Date: Tue Feb 12 21:47:56 2013 -0500
PR c++/56135
* pt.c (tsubst_copy_and_build): Don't forget any new
captures that arose from use of dependent names.
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;
+}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-02-14 11:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-14 11:59 C++ PATCH for c++/56135 (wrong 'this' capture) Dominique Dhumieres
-- strict thread matches above, loose matches on Subject: below --
2013-02-13 14:21 Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).