Possible C++ method signature warning feature?
Andrew Pinski
pinskia@gmail.com
Thu Aug 11 01:25:47 GMT 2022
On Wed, Aug 10, 2022 at 6:20 PM Paul Koning via Gcc <gcc@gcc.gnu.org> wrote:
>
> There's a C++ problem I keep running into, in a very large body of software with lots of subclassing.
>
> There's a base class that defines a set of interface methods, not all pure virtual (some define the default behavior). A number of subclasses override some but not all of these.
>
> Now I find myself changing the argument list of some of these methods, so I have to change the base class definitions and also track down all the subclass redefinitions. If I miss one of the latter, that subclass method is no longer called (it now just looks like an unrelated method with a different argument list that isn't used anywhere). Finding these things can be hard and time consuming.
>
> It would be helpful to have some way to mark a method as "this is supposed to be an override of a base class method", in other words "warn me if this method doesn't override some method in a base class".
C++11's overload keyword sounds exactly what you want.
https://en.cppreference.com/w/cpp/language/override
Thanks,
Andrew Pinski
>
> Does that sound like a possible thing to do, perhaps with some __attribute__ magic? Would it be interesting?
>
> paul
>
More information about the Gcc
mailing list