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 via email to