This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/7780: -Woverloaded-virtual generating false-positives
- From: Wolfgang Bangerth <bangerth at ticam dot utexas dot edu>
- To: Loren Osborn <linux_dr at yahoo dot com>
- Cc: gcc-bugs at gcc dot gnu dot org, <gcc-gnats at gcc dot gnu dot org>
- Date: Tue, 26 Nov 2002 16:53:37 -0600 (CST)
- Subject: Re: c++/7780: -Woverloaded-virtual generating false-positives
> > I think the example you give should indeed give a warning:
> > ----------------------
> > class A
> > {
> > public:
> > virtual int ThisFunctionShouldNotCauseAHidingWarning(char*);
> > virtual int ThisFunctionShouldNotCauseAHidingWarning(char*,int);
> > };
> >
> > class B : public A
> > {
> > public:
> > virtual int ThisFunctionShouldNotCauseAHidingWarning(char*,int);
> > };
> >
> > int main()
> > {
> > return 0;
> > }
> > -----------------------------------------
>
> As I understood it, this warning was to alert the programmer when they
> overload a (hopefully virutal) function that they intended to override.
>
> I am thinking of examples like:
> class A
> {
> public:
> virtual int ThisFunctionShouldCauseAHidingWarning(int);
> };
>
> class B : public A
> {
> public:
> virtual int ThisFunctionShouldCauseAHidingWarning(long);
> };
>
> If this was not the intent of this warning, perhaps another warning
> should catch this case.
No, this is particularly the case the warning was for. In this case you
are right.
However, the fact that in _my_ example the warning is triggered is that
overloading the function in B also hides the other function with the
different numbers of parameters. You'll see this if in my example you
replace main with this:
int main()
{
B b;
b.ThisFunctionShouldNotCauseAHidingWarning('c');
}
One would think that this calls the single parameter function of the base
class, but in fact the two-parameter function in the derived class also
hides the single-parameter function! So, even without
-Woverloaded-virtual, you'll get an _error_, not a _warning_. The warning
is there to warn you about this fact even if you do not attempt to
actually call the function.
Does this clarify the usefulness of the warning somehow?
Regards
Wolfgang
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@ticam.utexas.edu
www: http://www.ticam.utexas.edu/~bangerth