Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

use of the new override specifier

74 views
Skip to first unread message

Lynn McGuire

unread,
Jun 9, 2016, 4:30:26 PM6/9/16
to
So is anyone using the new C++11 override specifier? We have been retroactively adding it to our code with some surprising new
errors. We are using Visual Studio C++ 2015.
http://en.cppreference.com/w/cpp/language/override

Thanks,
Lynn

Ian Collins

unread,
Jun 9, 2016, 4:35:32 PM6/9/16
to
On 06/10/16 08:30 AM, Lynn McGuire wrote:
> So is anyone using the new C++11 override specifier? We have been
> retroactively adding it to our code with some surprising new errors.

Yes, I have been doing the same, mainly in older code that re-declared a
virtual function virtual.

I haven't found any new errors, but it does make the code easier to read
knowing a member function is virtual in the base class.

--
Ian

Wouter van Ooijen

unread,
Jun 9, 2016, 5:06:45 PM6/9/16
to
Op 09-Jun-16 om 10:30 PM schreef Lynn McGuire:
> So is anyone using the new C++11 override specifier? We have been
> retroactively adding it to our code with some surprising new errors.

I teach more than I program, but I use override whenever possible, and I
require the students to use it. And I'd like a (gcc) command line
parameter to make it a warning when it is omitted!

Wouter "Objects? No Thanks!" van Ooijen

Ian Collins

unread,
Jun 9, 2016, 5:12:30 PM6/9/16
to
Imagine compiling something big and old such as OpenOffice with that
warning turned on...

--
Ian

red floyd

unread,
Jun 9, 2016, 5:41:47 PM6/9/16
to
I thought OOo was written in Java? Not that it matters, your point
still stands.

Robert Wessel

unread,
Jun 9, 2016, 6:01:59 PM6/9/16
to
On Thu, 9 Jun 2016 14:41:37 -0700, red floyd <no....@its.invalid>
wrote:
It's mostly C++, although Java is far from a trivial component. Java
is needed for Base to function at all, but all the other components
will run without, with some features missing.

Good Guy

unread,
Jun 9, 2016, 6:10:56 PM6/9/16
to
On 09/06/2016 21:30, Lynn McGuire wrote:
 We are using Visual Studio C++ 2015.


Richard

unread,
Jun 9, 2016, 6:28:01 PM6/9/16
to
[Please do not mail me a copy of your followup]

Lynn McGuire <l...@winsim.com> spake the secret code
<njcjkn$1uk$1...@dont-email.me> thusly:

>So is anyone using the new C++11 override specifier?

clang-tidy (was clang-modernize) has an automatic transform that
applies override and removes virtual where it is appropriate.

I haven't seen people reporting problems with running this on their
code, but they would most likely already be using clang/gcc for their
compiler if they're running clang-tidy.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>

Richard

unread,
Jun 9, 2016, 6:29:58 PM6/9/16
to
[Please do not mail me a copy of your followup]

Ian Collins <ian-...@hotmail.com> spake the secret code
<dru4dj...@mid.individual.net> thusly:
...which is why you first run clang-tidy on it :)

Richard

unread,
Jun 9, 2016, 6:30:50 PM6/9/16
to
[Please do not mail me a copy of your followup]

Wouter van Ooijen <wou...@voti.nl> spake the secret code
<5759da43$0$22265$e4fe...@newszilla.xs4all.nl> thusly:
It seems there's a little bit of help from the compiler:
<http://stackoverflow.com/questions/29145476/requiring-virtual-function-overrides-to-use-override-keyword>

Also, clang-tidy can be run to detect places where override *could* be
used without making any changes to your program.

So you could use clang-tidy as a lint-like tool that simply reports
the problem without doing anything about it.

Paavo Helde

unread,
Jun 10, 2016, 1:15:31 AM6/10/16
to
Have been using it for many years already (it was available in MSVC long
before being standardized). Helps a lot during refactoring.


Marcel Mueller

unread,
Jun 10, 2016, 3:05:32 AM6/10/16
to
I leave it up to the IDE to identify overrides. This is more reliable.


Marcel

Richard

unread,
Jun 10, 2016, 1:54:06 PM6/10/16
to
[Please do not mail me a copy of your followup]

Marcel Mueller <news.5...@spamgourmet.org> spake the secret code
<njdorh$6n4$1...@gwaiyur.mb-net.net> thusly:

>I leave it up to the IDE to identify overrides. This is more reliable.

Nothing is more reliable than the compiler, IMO. IDEs are notorious
for taking shortcuts that result in false positives or negatives.

Lynn McGuire

unread,
Jun 10, 2016, 5:29:26 PM6/10/16
to
No way. This is production code.

Lynn

Marcel Mueller

unread,
Jun 11, 2016, 4:00:38 AM6/11/16
to
On 10.06.16 19.53, Richard wrote:
> Marcel Mueller <news.5...@spamgourmet.org> spake the secret code
> <njdorh$6n4$1...@gwaiyur.mb-net.net> thusly:
>
>> I leave it up to the IDE to identify overrides. This is more reliable.
>
> Nothing is more reliable than the compiler, IMO. IDEs are notorious
> for taking shortcuts that result in false positives or negatives.

Well, you are talking about parser bugs, aren't you?
True, from time to time the IDE is confused by the code. But programmers
tend to fail too. So if I have the choice to rely on the programmer or
on the IDE to identify an overridden method I would trust the IDE more.
That's why I do not call code that uses override more readable.

However, there are other use cases. I.e. in case of refactoring of the
overridden method the override keyword prevents accidentally missed
changes in derived classes. But this improves maintainability not
readability.


Marcel

Lynn McGuire

unread,
Jun 13, 2016, 1:19:32 PM6/13/16
to
Man, is it ever. I am converting our data storage from distributed to sparse and adding an owner argument to methods all over the
place. The override specifier is saving my bacon.

Lynn

Öö Tiib

unread,
Jun 13, 2016, 1:34:24 PM6/13/16
to
Hiding of members of base class is confusing regardless if
knowingly or by accident and if it is virtual function that
is hidden in such a way then that is even worse.

IOW I would often appreciate some warning in situations
that 'override' makes illegal even without that 'override'
present.

Juha Nieminen

unread,
Jun 14, 2016, 2:10:05 AM6/14/16
to
Marcel Mueller <news.5...@spamgourmet.org> wrote:
> I leave it up to the IDE to identify overrides. This is more reliable.

How exactly would the IDE know if a function is supposed to override
the same function in the base class if you don't tell it?

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
0 new messages