以下代码在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。