This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: overloaded virtual function warnings
- To: nathan at compsci dot bristol dot ac dot uk
- Subject: Re: overloaded virtual function warnings
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Mon, 08 Feb 1999 09:57:47 +0000
- CC: egcs at egcs dot cygnus dot com, mrs at cygnus dot com
- Organization: University of Bristol
- References: <36BB2AFB.DBD112CE@acm.org>
- Reply-To: nathan at compsci dot bristol dot ac dot uk
Nathan Sidwell (me) wrote:
> stuff about -Woverloaded-virtual
I'm not too surprised there were some objections to warning about missing
`virtual' on a derrived class virtual function. As the language permits that, I
don't think it sensible warn about. There seem to be no objections to warning
when a virtual function overrides a non-virtual function -- that's more likely
to be a mistake.
In looking at warn_hidden, which implements this flag, it seems the behaviour
is at variance with the documentation. gcc.info-2 says
`-Woverloaded-virtual'
Warn when a derived class function declaration may be an error in
defining a virtual function (C++ only). In a derived class, the
definitions of virtual functions must match the type signature of a
virtual function declared in the base class. With this option, the
compiler warns when you define a function with the same name as a
virtual function, but with a type signature that does not match any
declarations from the base class.
This seems to be saying that if A contains 'virtual int foo()', and B (derived
from A) contains 'virtual int foo(int)', I'll get a warning. If A contains both
'virtual int foo()' and 'virtual int foo(int)', but B contains only 'virtual
int foo()', I won't get a warning. The documentation isn't quite correct WRT
the language, a virtual function in a derrived class does not _have_ to match
the type signature in a base class, it's just that if it does not, it is not
overriding that base function.
However, the actual behaviour and the changelog entry are at variance with
this. Both are warned about.
Wed Jan 24 13:01:26 1996 Mike Stump <mrs@cygnus.com>
* class.c (finish_struct_1): Call warn_hidden if we want warnings
about overloaded virtual functions.
(warn_hidden): New routine to warn of virtual functions that are
hidden by other virtual functions, that are not overridden.