[cfe-dev] [Warnings] final class with virtual functions

Malcolm Parsons via cfe-dev cfe-dev at lists.llvm.org
Thu Dec 22 07:49:16 PST 2016


On 22 Dec 2016 2:33 p.m., "Aaron Ballman via cfe-dev" <
cfe-dev at lists.llvm.org> wrote:

On Wed, Dec 21, 2016 at 8:24 PM, Piotr Padlewski
<piotr.padlewski at gmail.com> wrote:
> Hi,
> I was wondering if we should warn about cases like this:
>
> struct A final {
>
>    virtual int foo () {return 42;}
>
>    // virtual doesn't make any sense because it is final base class
>
> };
>
>
> or
>
>
> struct A {
>
>   virtual int foo () final {return 42;}
>
>   // the same thing
>
> };
>
>
> So in both cases it sounds like a bug, specially in the first case.

I don't think it sounds like a bug (at least, nothing we'd want to
diagnose in the frontend).


I think it's a bug, but I also think it's unlikely to happen.

Prior to the override keyword, some coding style guidelines
recommended you write virtual on all virtual functions (instead of
just the first declaration of such a function in a base class) to make
it clear that the function is one that can be overridden.


The warning is about declaring a virtual method that cannot be overridden.
It wouldn't trigger for methods that are overriding, whether the override
keyword is used it not.


-- 
Malcolm Parsons
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161222/01cbc1d0/attachment.html>


More information about the cfe-dev mailing list