From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B21D53856240; Thu, 4 May 2023 16:40:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B21D53856240 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683218436; bh=Pg76CLVx2d5ibqN3fj9LCjrYK74BunYyFAXO99mBZXA=; h=From:To:Subject:Date:From; b=delB8ZX154sEeUK8Tg4k5FJ5AsaVt7TSdEohXbWmcGlGgeZysGIBCZ8oHmmXeQbGn H/lWpxAxuvaAv36sUKlcq2viWZCezlRmMcmiqUbvIzGg8Wg0+Gkr8AGGX1lIYDloYS k9KRZxmKQktAY6ZCyAngflK5zXznSuCLU1DZwww4= From: "psmith at gnu dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109740] New: -Woverloaded-virtual is too aggressive Date: Thu, 04 May 2023 16:40:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: psmith at gnu dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109740 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 signat= ure with some number of arguments, and the subclass has an overloaded method wi= th 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 argument= s. 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 thin= g.=20 If I call B.foo(10) it will give me an error. There's no way that the comp= iler 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 argumen= ts 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, bu= t I would prefer to keep the warning for in other situations that could potenti= ally 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 betw= een. There is an argument to be made that this, also, shouldn't cause a warning= .=20 I'm not sure how straightforward it is to determine "can't be converted" although there are some obvious ones.=