[PATCH] Warn when a virtual function tries to override a non-virtual one

Lubos Lunak l.lunak at centrum.cz
Fri Apr 4 10:54:30 PDT 2014


 Testcase:

struct B5 {
    void func();
};
struct S5 : public B5 {
    virtual void func();
};

 Here most likely S5::func() was meant to override B5::func() but doesn't 
because of missing 'virtual' in the base class. The attached patch warns 
about this case. I added the warning to -Woverloaded-virtual, because 
although technically it is not an overloaded virtual, it is exactly the same 
kind of a developer mistake, but if somebody insists I can update the patch 
to make it -Woverridden-non-virtual (which I think is a misnomer too :) ) or 
whatever you name it.

-- 
 Lubos Lunak
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-warn-when-a-virtual-function-tries-to-override-a-non.patch
Type: text/x-diff
Size: 5207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140404/df481b8d/attachment.patch>


More information about the cfe-commits mailing list