C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Detect non overriden function

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 21 Mar 2022 10:53:07 -0300
On Monday, 21 March 2022 03:48:56 -03 organicoman wrote:
> "Because readAll is not virtual."
>
> 😱, that's true. It's not!!!!
> Wow, that's definitely another reason to flag it.

So you want the compiler to emit a warning that you're calling a method that
was not overriden and was not meant to be overridden? Are you sure you
understand the documentation of the class you're trying to use in the first
place?

read readLine and readAll are all front-end, non-virtual functions that call
the back-end virtual readBlock function. That one is a pure virtual, so every
single class deriving from QIODevice must provide its own implementation.

There are other virtual functions in the class that derived classes often
override but don't have to, like seek() or bytesAvailable(). It's often wrong
to use the base implementation in a derived class.

But here's the thing: the derived class's implementer makes that choice, not
you as a user. There's no reason for you to get a warning, if the class
implementer has done their job properly. If you think that they haven't and
that there's a bug, that's a different story, but then there s little the
standard and the compilers can help with.

Except for the -fkeep-programmers-inline option we've been asking of GCC for
some time. Please make a proposal for that one and post next Friday.

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

Received on 2022-03-21 13:53:12