This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH: Better -Woverloaded-virtual diagnostics


Jason Merrill wrote:
> 
> >>>>> Nathan Sidwell <nathan@acm.org> writes:
>  > In this case I don't think it sensible to warn any way, because one
>  > might well want to override a subset of virtual functions -- what one
>  > doesn't want to do is introduce a new virtual function that looks
>  > similar to a base virtual function.
> 
> I disagree.  That is also useful to check, but it is dangerous to override
> some overloads and not others -- the ones that are not overridden will be
> hidden, causing unexpected overload results.
This hiding is true, but the same behaviour occurs for non-virtual functions.
Consider,

struct A {
  int fn(float);
  int fn(int);
};

struct B : public A {
  int fn(float);
};

B::fn(float) hides A::fn(int), yet we don't issue a warning about that.

Whilst it may be useful to issue such a warning, I think it is a separate issue
to what -Woverloaded-virtual should be trying to warning about. I don't see
what's special about a virtual being hidden in this way, as opposed to a
non-virtual -- of course I could be missing something.

May be the flag should be -Woverridden-virtual, rather than
-Woverloaded-virtual?
What you're worried about might be better served by a -Whidden-overload flag,
and cured by a using declaration (when they're dealt with properly).

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]