This is the mail archive of the gcc-patches@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]

Re: PR c++/5645 gcc warns that pure virtual class not explicitly initialized


Manuel López-Ibáñez wrote:

> The patch below avoids this warning by checking for nearly emptiness.
> I am not sure that this is the correct approach for 100% cases, since
> I ignore all specific cases that should be warned and that shouldn't.
> 
> Bootstrapped and regression tested.
> 
> OK to commit?

Nathan, Jason, are you agreed that PR c++/5645 is in fact a bug?  This
is one of these situations where we need to decide if we're warning
about things that probably are a problem, or about things that could
become a problem.  In particular, if the base class has no data, then
there's often no actual problem with not invoking the base class copy
constructor -- but there certainly might be a problem, and, if the
future, the base class were to get data, then there would likely be a
problem.

(I don't really have an opinion here; my personal coding style would
probably be to put in the base class copy constructor call, and let the
compiler optimize it away, just to future-proof my code.)

Manuel, if we all agree that we don't want to warn in this situation,
then I'd suggest that we check that the base class is nearly empty and
that the base class copy constructor is not user-defined.  I would think
we would certainly want to warn about:

struct base {
  base(const base& b);
  virtual void f() = 0;
};

struct derived : public base {
  derived(const derived &d) {}
};

because we don't know what the base class copy constructor does, but the
fact that it is there suggests that it's author wants us to call it.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


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