Compiler behaviour when constructing virtual base class
<p>Consider this piece of code:</p>

<pre><code>#include &lt;iostream&gt;

class A {
  public:
    A(int s) { std::cout &lt;&lt; "A(" &lt;&lt; s &lt;&lt; ")\n"; }
};

class B1 : virtual public A {
  public:
    B1(int s1, int s2)
        : A{s1} { std::cout &lt;&lt; "B1(" &lt;&lt; s1 &lt;&lt; "," &lt;&lt; s2 &lt;&lt; ")\n"; }
};

class B2 : virtual public A {
  public:
    B2(int s1, int s2)
        : A{s1} { std::cout &lt;&lt; "B2(" &lt;&lt; s1 &lt;&lt; "," &lt;&lt; s2 &lt;&lt; ")\n"; }
};

class C1 : public B1, public B2 {
  public:
    C1() : B1{1,2}, B2{3,4}, A{5} {}
};

class C2 : public B1, public B2 {
  public:
    C2() : B1(1,2), B2(3,4), A{5} {}
};

int main()
{
    std::cout &lt;&lt; "Create c1:\n";
    C1 c1;

    std::cout &lt;&lt; "\n";
    std::cout &lt;&lt; "Create c2:\n";
    C2 c2;

}
</code></pre>

<p>Class A is a virtual base class of B1 and B2. Classes C1 and C2 are identical, except that C1 uses <code>{...}</code> and C2 uses <code>(...)</code> to construct B1 and B2.</p>

<p>Because of the virtual inheritance used here, class A should be constructed as part of the construction of C1 or C2.</p>

<p>If I compile this code with Microsoft VS2015, it produces this output when running:</p>

<pre><code>Create c1:
A(5)
B1(1,2)
B2(3,4)

Create c2:
A(5)
B1(1,2)
B2(3,4)
</code></pre>

<p>which is exactly what I would expect.</p>

<p>But if I compile it with GCC (6.1.0) it produces this output:</p>

<pre><code>Create c1:
A(5)
A(1)
B1(1,2)
A(3)
B2(3,4)

Create c2:
A(5)
B1(1,2)
B2(3,4)
</code></pre>

<p>Here, A's constructor is called three times when constructing c1, but only once when constructing c2.</p>

<p>Is this a bug in GCC or have I misunderstood something?</p>