------- Comment #5 from reichelt at gcc dot gnu dot org  2005-11-29 20:33 
-------
This is not a bug in GCC. The code is invalid.

Let's consider the following simplified example which is just a
part of the diamond:

  A0
  |
  A
 /
B

==========================
struct A0
{
    A0(int);
};

struct A : virtual A0
{
    A() : A0(0) {}
};

struct B : virtual A
{
    B() : A() {}
};
==========================

[12.6.2]/6 of the standard states:

  All sub-objects representing virtual base classes are initialized
  by the constructor of the most derived class. If the constructor
  of the most derived class does not specify a mem-initializer for a
  virtual base class V, then V's default constructor is called to
  initialize the virtual base class subobject. If V does not have an
  accessible default constructor, the initialization is ill-formed.
  A mem-initializer naming a virtual base class shall be ignored
  during execution of the constructor of any class that is not the
  most derived class.

The first sentence means that A *and* A0 are initialized by the
constructor of B. The second sentence says that V (which is A0 in
our case) is default constructed since B's constructor does not
specify a mem-initializer for V==A0. The next sentence says that
the example is ill-formed since V==A0 does not have an accessible
default constructor. That's why g++ gives the following diagnostic:

  bug.cc: In constructor 'B::B()':
  bug.cc:13: error: no matching function for call to 'A0::A0()'
  bug.cc:3: note: candidates are: A0::A0(int)
  bug.cc:2: note:                 A0::A0(const A0&)

The last sentence says that A0(0) is ignored in the constructor
of A when called by B (which makes sense, since A0 should be
constructed directly by B's constructor).


-- 

reichelt at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |reichelt at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20207

Reply via email to