C++ Logo


Advanced search

Re: [std-proposals] enable very strict use of 'virtual', 'override', etc.

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 02 May 2023 08:25:06 -0700
On Tuesday, 2 May 2023 08:17:09 PDT Jason McKesson via Std-Proposals wrote:
> > We also now have
> > over 10 years of experience with the current keywords, so you need to
> > reflect the state of the art and how compilers warn these days (the
> > "inconsistent use of override" warning).
> Those aren't warnings; it is ill-formed to use `override` on a
> function declaration that doesn't match a virtual base class
> equivalent ([class.virtual]/5, from C++20).

No, I really meant the inconsistent use of override, such as this:

struct Base
    virtual void f();
    virtual void g();

struct Derived : Base
    void f() override;
    void g();

See https://clang.godbolt.org/z/aWaGnxYob

Clang automatically warns if you use override in some overrides and not
others, without -Wsuggest-override.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-05-02 15:25:08