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

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).