public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "micis at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/20423] New: Warning -Woverloaded-virtual triggers to often
Date: Fri, 11 Mar 2005 10:34:00 -0000	[thread overview]
Message-ID: <20050311103418.20423.micis@gmx.de> (raw)

I tried the warning option -Woverloaded-virtual in my application 
and it was very usefull to me (I managed to find a serious bug). 

However, the warning triggers triggers too often. 
Consider the following test case:


class Foo
{
public: virtual void Func(int);
        virtual void Func(int, int);
};

class Baz: public Foo
{
public: virtual void Func(int, int);
};


When compiled with gcc40 I get:

warntest.cpp:4: warning: 'virtual void Foo::Func(int)' was hidden
warntest.cpp:10: warning:   by 'virtual void Baz::Func(int, int)'

The warning is triggered only if I try to overload one of the two
Func in Foo. If both Func are declared in Baz no warning is issued.

Since our application it is common to overload only some methods of
a base class I get thousands of these warnings.


This is also not conforming to the "specification" in
http://gcc.gnu.org/ml/gcc-bugs/1999-08n/msg01069.html

  Warn when a derived class function declaration may be an error in
  defining a virtual function.  In a derived class, the definitions of
  virtual functions must match the type signature of a virtual
  function declared in the base class.  With this option, the compiler
  warns when you define a function with the same name as a virtual
  function, but with a type signature that does not match any
  declarations from the base class.
 

By the way: I find this much better understandable than the description
in the gcc manual

`-Woverloaded-virtual (C++ only)'                                   
     Warn when a function declaration hides virtual functions from a
     base class.  For example, in:                                  
                                                                    
          struct A {                                                
            virtual void f();                                       
          };                                                        
                                                                    
          struct B: public A {                                      
            void f(int);                                            
          };                                                        
                                                                    
     the `A' class version of `f' is hidden in `B', and code like:  
                                                                    
          B* b;                                                     
          b->f();                                                   
                                                                    
     will fail to compile.                                          

Michael Cieslinski

-- 
           Summary: Warning -Woverloaded-virtual triggers to often
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: micis at gmx dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20423


             reply	other threads:[~2005-03-11 10:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-11 10:34 micis at gmx dot de [this message]
2005-03-11 15:12 ` [Bug c++/20423] " pinskia at gcc dot gnu dot org
2005-03-11 17:30 ` micis at gmx dot de
2005-03-29 14:10 ` pinskia at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050311103418.20423.micis@gmx.de \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).