https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68903
Bug ID: 68903
Summary: missing default initialization of member when combined
with virtual imheritance
Product: gcc
Version: 5.2.1
Status: UNCONFIRMED
Severity: blocker
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: spam at trzeci dot pl
Target Milestone: ---
B::b is not constructed at all in the following code:
struct Attribute
{
int i;
Attribute( int _i ) :i(_i) {}
};
struct O
{
Attribute createAttribute(int i)
{
return Attribute(i);
}
};
struct A : public O
{
Attribute a = createAttribute(1);
};
struct B : public virtual A
{
Attribute b = createAttribute(2);
};
#include <iostream>
int main()
{
B *b = new B;
std::cout << b->a.i << " " << b->b.i << std::endl;
return 0;
}
compiled with -std=c++14
outputs: 1 0
should output: 1 2
probable cause:
combination of virtual inheritance in B with default initialization
of attribute from call to inherited method.
The bug exists in 4.9.2 and 5.2.1 (maybe other)
The bug is independent from any other compiler options.
Adding any of default constructors does not help.
Removing virtual inheritance helps.
Adding virtual inheritance between A and O helps.
Removing method call in default initialization of B::b helps.
Moving initializer of B::b to constructor also helps.