C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Detect non overriden function

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 21 Mar 2022 09:38:18 -0400
On Mon, Mar 21, 2022 at 6:56 AM organicoman via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Hello,
> You are a genius, you almost hit the target.
> "deprecated" simulates what i want to achieve.
> 1- allow the function to be called
> 2- issue a warning
> A couple of drawbacks are:
> - it is still triggered when called on the base class instances.(which is not desired)

Warnings are compile-time. The compiler doesn't know when you're
calling a derived class if the code doing the calling only sees a base
class pointer/reference. See this Godbolt example:
https://gcc.godbolt.org/z/5MoPnb8d4

So the warning will only appear when you're *knowingly* calling the
derived class function. Perhaps you thought that the attribute was put
onto the base class function instead of the derived class one?

> - all other derived classes will trigger the warning even if they don't subscribe to it.

Again, they will not; see the example above.

> - it doesn't differentiate between overriden members, and hidden member functions(non virtual)

This isn't a case of "hidden member functions". Your `readAll` example
isn't *hidden*; the derived class doesn't provide a `readAll`
function. The QIOBase base class implementation is being used because
it's a perfectly valid function.

Received on 2022-03-21 13:38:41