带有虚拟继承的初始化列表中的lambda捕获的gcc错误?

时间:2017-05-02 23:12:42

标签: c++ gcc lambda

以下代码在gcc-4.9,5.4和6.3下使用std = c ++ 11进行段错误,但在clang-3.7和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;
}

这是gcc中的错误吗? 删除虚拟继承修复了segfault。

1 个答案:

答案 0 :(得分:1)

这是作为gcc的错误提交的,并已确认。

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