[PATCH] -Woverloaded-virtual

David Blaikie dblaikie at gmail.com
Wed Jul 30 13:42:28 PDT 2014


I made some improvements to -Woverloaded-virtual a while ago and
semi-deliberately chose the behavior you're observing (in the sense
that it seemed like this warning was for catching the case where you
tried to override a virtual function but accidentally ended up
overloading it).

The situation you've described might be better suited to a separate
flag - and should warn even if there's no overriding going on. This
could fire on non-virtual functions too:

struct base {
  void func(char);
};

struct derived: base {
  void func(int);
};

We currently don't warn here.

On Wed, Jul 30, 2014 at 1:30 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
> I believe the following patch addresses a slight deficiency in our
> -Woverloaded-virtual warning check. Specifically, it causes the
> following code to warn (which matches GCC's behavior):
>
> struct base {
>   virtual void foo(int I) {}
>   virtual void foo(char C) {}
> };
>
> struct derived : public base {
>   void foo(int I2) override {}
> };
>
> It does this by continuing to check other methods instead of early
> returning out of processing them when an exact signature match is
> encountered. I believe this is an improvement because it catches
> problems like:
>
> derived d;
> d.foo('1');
>
> Where derived::foo(int) is called when the user may expect
> base::foo(char) to be called.
>
> ~Aaron
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list