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

David Röthlisberger david at rothlis.net
Mon Aug 15 01:31:42 PDT 2011


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.)

And thoughts on my implementation of it? (This is the first time I've ever looked at the clang source code.)

Cheers,
David Röthlisberger.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Note-to-explain-that-the-most-derived-class-must-exp.patch
Type: application/octet-stream
Size: 5664 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110815/93e349e7/attachment.obj>


More information about the cfe-commits mailing list