[cfe-commits] [PATCH] Helpful message for uninitialized virtual base
Eli Friedman
eli.friedman at gmail.com
Mon Aug 15 02:14:59 PDT 2011
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
More information about the cfe-commits
mailing list