public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53619] New: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism
@ 2012-06-09 15:48 vincenzo.innocente at cern dot ch
2012-06-09 16:16 ` [Bug c++/53619] " vincenzo.innocente at cern dot ch
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-06-09 15:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53619
Bug #: 53619
Summary: [c++11, regression] wrong capture of "this" in lambda
in case of polymorphism
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: vincenzo.innocente@cern.ch
in this example "x" is wrongly captured
./a.out
in foo 1
in lambda 4203472
Segmentation fault (core dumped)
removing the inheritance from B works "as expected"
It starts at the same time I had to capture "this" explicitly…
(sorry, only now had the time to debug it fully and reduce it some how)
#include<iostream>
struct CA {
const int x;
constexpr CA(int i) : x(i){}
};
struct B {
virtual ~B(){}
};
struct A : public B, private CA {
A(CA const c) : CA(c){}
int foo(int *, int);
};
int A::foo(int * h, int l) {
std::cout << "in foo " << x << std::endl;
int a=0;
auto k = [&a, &h ,this](int i) {
std::cout << "in lambda " << x << std::endl;
a+=h[x+i];
};
for (int i=0; i!=l; ++i)
k(i);
return a;
}
int main(int l, char **) {
CA ca(1);
A a(ca);
int h[l+2]; h[0]=l;
std::cout << a.foo(h,l) << std::endl;
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/53619] [c++11, regression] wrong capture of "this" in lambda in case of polymorphism
2012-06-09 15:48 [Bug c++/53619] New: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism vincenzo.innocente at cern dot ch
@ 2012-06-09 16:16 ` vincenzo.innocente at cern dot ch
2012-06-09 17:04 ` [Bug c++/53619] [c++11, regression] wrong capture of "this" in lambda in case of multiple inheritance vincenzo.innocente at cern dot ch
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-06-09 16:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53619
--- Comment #1 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2012-06-09 16:16:32 UTC ---
reduced a bit showing how the offset is wrongly computed
struct CA {
int x;
};
struct B {
virtual ~B(){}
};
struct A : public B , CA {
int foo(int);
};
int A::foo(int l) {
std::cout << "in foo " << x << " " << (void *)(&x) << std::endl;
auto k = [this](int i) {
std::cout << "in lambda " << x << " " << (void *)(&x) << std::endl;
return x+i;
};
return k(l);
}
int main(int l, char **) {
A a; a.x=1;
std::cout << a.foo(l) << std::endl;
}
c++ -O2 -std=gnu++11 lambda_this2.cpp
./a.out
in foo 1 0x7fff6c4de178
in lambda 4198320 0x7fff6c4de170
4198321
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/53619] [c++11, regression] wrong capture of "this" in lambda in case of multiple inheritance
2012-06-09 15:48 [Bug c++/53619] New: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism vincenzo.innocente at cern dot ch
2012-06-09 16:16 ` [Bug c++/53619] " vincenzo.innocente at cern dot ch
@ 2012-06-09 17:04 ` vincenzo.innocente at cern dot ch
2012-06-09 22:36 ` hjl.tools at gmail dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-06-09 17:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53619
--- Comment #2 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2012-06-09 17:04:10 UTC ---
an even simpler test
cat lambda_this2.cpp
#include<cassert>
struct C {
int x;
};
struct B {
int q;
};
struct A : public B , C {
void foo();
};
void A::foo() {
auto k = [this]() {return (void *)(&x);};
assert(k()==(void *)(&x));
}
int main(int l, char **) {
A a; a.foo();
}
c++ -std=gnu++11 lambda_this2.cpp; ./a.out
a.out: lambda_this2.cpp:14: void A::foo(): Assertion `k()==(void *)(&x)'
failed.
Aborted (core dumped)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/53619] [c++11, regression] wrong capture of "this" in lambda in case of multiple inheritance
2012-06-09 15:48 [Bug c++/53619] New: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism vincenzo.innocente at cern dot ch
2012-06-09 16:16 ` [Bug c++/53619] " vincenzo.innocente at cern dot ch
2012-06-09 17:04 ` [Bug c++/53619] [c++11, regression] wrong capture of "this" in lambda in case of multiple inheritance vincenzo.innocente at cern dot ch
@ 2012-06-09 22:36 ` hjl.tools at gmail dot com
2012-07-03 4:01 ` [Bug c++/53619] [4.8 regression] [C++11] " jason at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: hjl.tools at gmail dot com @ 2012-06-09 22:36 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53619
H.J. Lu <hjl.tools at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-06-09
CC| |jason at gcc dot gnu.org
Ever Confirmed|0 |1
--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> 2012-06-09 22:36:39 UTC ---
It is caused by revision 185768:
http://gcc.gnu.org/ml/gcc-cvs/2012-03/msg01099.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/53619] [4.8 regression] [C++11] wrong capture of "this" in lambda in case of multiple inheritance
2012-06-09 15:48 [Bug c++/53619] New: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism vincenzo.innocente at cern dot ch
` (2 preceding siblings ...)
2012-06-09 22:36 ` hjl.tools at gmail dot com
@ 2012-07-03 4:01 ` jason at gcc dot gnu.org
2012-07-03 5:04 ` jason at gcc dot gnu.org
2012-07-03 5:06 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2012-07-03 4:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53619
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |jason at gcc dot gnu.org
|gnu.org |
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/53619] [4.8 regression] [C++11] wrong capture of "this" in lambda in case of multiple inheritance
2012-06-09 15:48 [Bug c++/53619] New: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism vincenzo.innocente at cern dot ch
` (3 preceding siblings ...)
2012-07-03 4:01 ` [Bug c++/53619] [4.8 regression] [C++11] " jason at gcc dot gnu.org
@ 2012-07-03 5:04 ` jason at gcc dot gnu.org
2012-07-03 5:06 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2012-07-03 5:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53619
--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> 2012-07-03 05:03:45 UTC ---
Author: jason
Date: Tue Jul 3 05:03:34 2012
New Revision: 189191
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189191
Log:
PR c++/53619
* pt.c (in_template_function): New.
* cp-tree.h: Declare it.
* class.c (build_base_path, resolves_to_fixed_type_p): Use it.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this5.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/class.c
trunk/gcc/cp/cp-tree.h
trunk/gcc/cp/pt.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/53619] [4.8 regression] [C++11] wrong capture of "this" in lambda in case of multiple inheritance
2012-06-09 15:48 [Bug c++/53619] New: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism vincenzo.innocente at cern dot ch
` (4 preceding siblings ...)
2012-07-03 5:04 ` jason at gcc dot gnu.org
@ 2012-07-03 5:06 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2012-07-03 5:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53619
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.8.0
--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2012-07-03 05:06:17 UTC ---
Fixed.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-07-03 5:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-09 15:48 [Bug c++/53619] New: [c++11, regression] wrong capture of "this" in lambda in case of polymorphism vincenzo.innocente at cern dot ch
2012-06-09 16:16 ` [Bug c++/53619] " vincenzo.innocente at cern dot ch
2012-06-09 17:04 ` [Bug c++/53619] [c++11, regression] wrong capture of "this" in lambda in case of multiple inheritance vincenzo.innocente at cern dot ch
2012-06-09 22:36 ` hjl.tools at gmail dot com
2012-07-03 4:01 ` [Bug c++/53619] [4.8 regression] [C++11] " jason at gcc dot gnu.org
2012-07-03 5:04 ` jason at gcc dot gnu.org
2012-07-03 5:06 ` jason at gcc dot gnu.org
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).