https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109740
Bug ID: 109740 Summary: -Woverloaded-virtual is too aggressive Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: psmith at gnu dot org Target Milestone: --- I understand the impetus for the -Woverloaded-virtual warning but I think it should be further constrained, or maybe broken into levels of severity that can be enabled. The issue I'm running into is that a superclass has a virtual method signature with some number of arguments, and the subclass has an overloaded method with a different number of arguments. For example: struct A { virtual void foo(int); }; struct B : public A { void foo(); }; We do this kind of thing all the time because the subclass's version of this method has more knowledge, or whatever, and doesn't need the extra arguments. However, this fires the overloaded-virtual warning. I don't think this warrants a warning: if I call B.foo() then it will always do the right thing. If I call B.foo(10) it will give me an error. There's no way that the compiler could ever call the wrong thing "behind my back" due to some sort of type conversion that is not obvious from the code, because the number of arguments are different: either it does exactly what I expect and there's no need for a warning, or I get an error and there's no need for a warning. This subclassing capability is (IMO) useful and shouldn't be restricted, but I would prefer to keep the warning for in other situations that could potentially cause misbehavior. Would it be possible to suppress this warning if the overload can't possibly conflict due to number of arguments? There is also the possibility that a subclass method has the same number of arguments but they are of incompatible types which cannot be converted between. There is an argument to be made that this, also, shouldn't cause a warning. I'm not sure how straightforward it is to determine "can't be converted" although there are some obvious ones.