From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12953 invoked by alias); 3 Feb 2012 09:07:35 -0000 Received: (qmail 12941 invoked by uid 22791); 3 Feb 2012 09:07:34 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Feb 2012 09:07:20 +0000 From: "mlg7 at yandex dot ru" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/52103] New: need a finer control over -Woverloaded-virtual Date: Fri, 03 Feb 2012 09:07:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mlg7 at yandex dot ru X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-02/txt/msg00322.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D52103 Bug #: 52103 Summary: need a finer control over -Woverloaded-virtual Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: mlg7@yandex.ru Let me first explain my use case. I have a large existing non-gcc source which I am porting to a platform supported by gcc. Due to the difference in dialects, I have to insert const modifiers for the function parameters. But when I change the signature of a base class by inserting const, it does not affect the derived classes -- instead, it just breaks inheritance. This is where -Woverloaded-virtual com= es to play. Unfortunately, it generates too much noise, rendering the feature almost unusable for this case. Indeed, the best place to hide an important message= is a hundred of useless messages of the same sort. (So this is a usability iss= ue.) Considering that -Woverloaded-virtual is rather doing what its name suggest= s, I propose to implement two finer-tuned options. -Woverloaded-modifiers gives a warning when the two signatures differ only in modifiers like const. (Consider also volatile and restrict.) struct Base{ void f(Base& x){} }; struct Derived: public Base{ void f(const Base& x){} }; -Woverloaded-compatible gives a warning when the two signatures differ in parameter classes, but on= e of the classes is a descendant of the other. struct First{ void g(Base&x){} }; struct Second{ void g(Derived&x){} }; I underline that -Woverloaded-modifiers and -Woverloaded-compatible should = not be limited to virtual functions: virtual could be implied if the function is virtual in the base class. (You may disagree with me here, in this case I w= ant to hear your arguments.) (I do not insist on namely these names, maybe you have some better suggestion(s), but I insist on the functionality.) As to -Woverloaded-virtual, I think, it should be left as it is. Now some code example. Note that with -Woverloaded-modifiers -Woverloaded-compatible there should be no warning for struct ThereIsNoProb= lem because the argument types are unrelated. $cat inher4.cpp=20 #include struct Base{ void f(const Base& x){printf("Base.f()\n");} }; struct Derived: public Base{ void f(Base& x){printf("Derived.f()\n");} }; struct First{ virtual void g(Base&x){printf("First.g()\n");} }; struct Second:public First{ virtual void g(Derived&x){printf("Second.g()\n"= );} }; struct ThereIsNoProblem:public First{ virtual void g(int x){printf("ShouldBeValid.g()");} }; int main() { Base x; Derived y; Base*py=3D&y; y.f(x); py->f(Base()); Second z; First*pz=3D&z; //z.g(x); // error: no matching function for call to =E2=80=98Second::g= (Base&)=E2=80=99 z.g(y); pz->g(x); pz->g(y); } $g++ -Woverloaded-virtual inher4.cpp=20 inher4.cpp:6:28: warning: =E2=80=98virtual void First::g(Base&)=E2=80=99 wa= s hidden inher4.cpp:7:42: warning: by =E2=80=98virtual void Second::g(Derived&)=E2= =80=99 inher4.cpp:6:28: warning: =E2=80=98virtual void First::g(Base&)=E2=80=99 wa= s hidden inher4.cpp:8:52: warning: by =E2=80=98virtual void ThereIsNoProblem::g(in= t)=E2=80=99 $./a.out=20 Derived.f() Base.f() Second.g() First.g() First.g() $