[cfe-commits] [PATCH] Helpful message for uninitialized virtual base

Sean Hunt scshunt at csclub.uwaterloo.ca
Mon Aug 15 02:16:56 PDT 2011


On Mon, Aug 15, 2011 at 02:14, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Mon, Aug 15, 2011 at 1:31 AM, David Röthlisberger <david at rothlis.net>
> wrote:
> > In C++ when you have the following inheritance hierarchy:
> >
> >    Base <--(virtual)-- Middle <---- Derived
> >
> > if Base has no default constructor, then the most-derived class must
> explicitly call the virtual base's constructor.
> >
> > Clang's current error message is:
> >
> >    constructor for 'Derived' must explicitly initialize the base class
> 'Base'
> >    which does not have a default constructor
> >
> > Maybe I'm a bit slow, but when I encountered this error I spent about an
> hour trying to figure out why my initialization of Base in Middle's
> constructor wasn't being found. This patch adds the following note:
> >
> >    note: because 'Base' is a virtual base, the most-derived class must
> explicitly
> >    initialize it
> >
> > Is this a good idea? Unnecessary? Is it really clang's job to educate the
> user on the more obscure aspects of C++? (I would argue that yes, we need
> all the help we can get.)
>
> I think a more subtle approach might be more appropriate: we could
> change to existing diagnostic to explicitly say "virtual base class"
> instead of just "base class".  Hopefully, that would be enough to
> point the user in the right direction.
>
> -Eli
>

I can't think of any reason we shouldn't have a note showing where it is
virtual.

Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110815/2a4e308e/attachment.html>


More information about the cfe-commits mailing list