C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Detect non overriden function

From: organicoman <organicoman_at_[hidden]>
Date: Mon, 21 Mar 2022 20:56:24 +0400
Warnings are compile-time. The compiler doesn't know when you'recalling a derived class if the code doing the calling only sees a baseclass pointer/reference. See this Godbolt example:https://gcc.godbolt.org/z/5MoPnb8d4So the warning will only appear when you're *knowingly* calling thederived class function. Perhaps you thought that the attribute was putonto the base class function instead of the derived class one?Yes Jason, I tried to put the [[deprecated]] attribute on the base class,If i put it on the derived class like in your example line 10, i will be obliged to override the method, which will contradict the purpose of what I'm proposing.The proposal is " I want to be notified that I'm calling a non overriden virtual method" through its dervied class, but only for those derived classes that explicitly subscribe to that warning. In plain English:"Headsup end User, i'm a derived class, but you are calling a virtual method i inherited from my base class which i didn't override, maybe you should check if that base class implementation fits your use case, or maybe you should derive and override"From this you can deduce that:-the decorator should only be in the dervied class which specifically want to trigger the warning.-that method should not be overriden in the same derived class.-the base class's method in question must be virtual, otherwise it is obvious you are calling the base class, unless you hide it with a local implementation, which is not in the scope of this proposal.-in the implementation of the derived class, in any of its method, if they call that decorated function it should not trigger that warning since it is intrinsic to its class. Just the outside user should have that warning, i.e make a difference between: this->foo(); //doesn't triggerAnd instance.foo(); //trigger the warningI think the only way to implement this is through an analyzer like Clazy or similar, like i pointed out to Magnus.Thanks again Jason, you don't know how much your answers are appreciated. NadSent from my Galaxy
-------- Original message --------From: Jason McKesson via Std-Proposals <std-proposals_at_[hidden]> Date: 3/21/22 5:38 PM (GMT+04:00) To: std-proposals_at_[hidden] Cc: Jason McKesson <jmckesson_at_[hidden]> Subject: Re: [std-proposals] Detect non overriden function 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'recalling a derived class if the code doing the calling only sees a baseclass pointer/reference. See this Godbolt example:https://gcc.godbolt.org/z/5MoPnb8d4So the warning will only appear when you're *knowingly* calling thederived class function. Perhaps you thought that the attribute was putonto 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` exampleisn't *hidden*; the derived class doesn't provide a `readAll`function. The QIOBase base class implementation is being used becauseit's a perfectly valid function.-- Std-Proposals mailing listStd-Proposals_at_[hidden]://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-03-21 16:56:32