Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc bug with lambda capture of this in initialization list with virtual inheritance?

Tags:

c++

gcc

lambda

The following code segfaults under gcc-4.9, 5.4, and 6.3 with std=c++11, but compiles and runs fine under clang-3.7, and VS2015 Update 3.

struct A
{
    int Func() { return x++; }
    int x = 5;
};

struct B
{
    B(int) {}
};

struct Derived : public virtual A, public B
{
    Derived()
      : A()
      // , B(this->Func()) // This works!
      , B([this](){ return this->Func(); }()) // But this segfaults.
    {
    }
};

int main()
{
    Derived c;
}

Is this a bug in gcc? Removing virtual inheritance fixes the segfault.

like image 942
Andrew Avatar asked May 02 '17 23:05

Andrew


1 Answers

This has been filed as a bug with gcc, and confirmed.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81051

like image 110
Andrew Avatar answered Nov 17 '22 23:11

Andrew