This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11159] erroneous warning in copy ctor with virtual inheritance



------- Comment #9 from wotte at dre dot vanderbilt dot edu  2006-03-09 22:44 -------
In some cases, this warning can also be impossible to address and may be
buggy/erroneous.  Consider the following example:
========
struct A
{
  A ();
};

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

struct C :  virtual B
{
  C ();
};

template <typename Base>
struct E : Base
{
  E ();

  E (E const &)
  {
  };
};

E<C> foo;
E<C> bar (foo);
====
Produces the following diagnostic:

test.cpp: In copy constructor 'E<Base>::E(const E<Base>&) [with Base = C]':
test.cpp:27:   instantiated from here
test.cpp:21: warning: base class 'struct A' should be explicitly initialized in
the copy constructor
test.cpp:21: warning: base class 'struct B' should be explicitly initialized in
the copy constructor
test.cpp:21: warning: base class 'struct C' should be explicitly initialized in
the copy constructor

If I make an immediately obvious fix by explicitly initializing Base:

========
struct A
{
  A ();
};

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

struct C :  virtual B
{
  C ();
};

template <typename Base>
struct E : Base
{
  E ();

  E (E const &)
    : Base ()
  {
  };
};

E<C> foo;
E<C> bar (foo);

====

I am presented with the following diagnostic:
test.cpp: In copy constructor 'E<Base>::E(const E<Base>&) [with Base = C]':
test.cpp:28:   instantiated from here
test.cpp:21: warning: base class 'struct A' should be explicitly initialized in
the copy constructor
test.cpp:21: warning: base class 'struct B' should be explicitly initialized in
the copy constructor

In this case, E can't explicitly initialize A or B, because E can't assume that
either is present as a parent of Base.  This is also likely erroneous because E
shouldn't have to explicitly initialize the parents of Base... That should be
handled by the copy constructor of Base.


-- 

wotte at dre dot vanderbilt dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wotte at dre dot vanderbilt
                   |                            |dot edu


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]