public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/20423] New: Warning -Woverloaded-virtual triggers to often
@ 2005-03-11 10:34 micis at gmx dot de
  2005-03-11 15:12 ` [Bug c++/20423] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: micis at gmx dot de @ 2005-03-11 10:34 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
  2005-03-11 10:34 [Bug c++/20423] New: Warning -Woverloaded-virtual triggers to often micis at gmx dot de
@ 2005-03-11 15:12 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-11 15:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-11 15:11 -------
Hmm, ICC gives:
t.cc(7): warning #654: overloaded virtual function "Foo::Func" is only partially overridden in class "Baz"
  class Baz: public Foo
        ^

t.cc(14): error #165: too few arguments in function call
    b->Func(1);
             ^

compilation aborted for t.cc (code 2)

The warning is correct because Func(int) is still hidden in the supper class and you cannot use it:
class Foo
{
public: virtual void Func(int);
        virtual void Func(int, int);
};

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

void g(Baz *b)
{
  b->Func(1);
}


Maybe we should do the warning which ICC is giving instead of the one which we give right now.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor
           Keywords|                            |diagnostic


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
  2005-03-11 10:34 [Bug c++/20423] New: Warning -Woverloaded-virtual triggers to often micis at gmx dot de
  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
  2 siblings, 0 replies; 4+ messages in thread
From: micis at gmx dot de @ 2005-03-11 17:30 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From micis at gmx dot de  2005-03-11 17:30 -------
I think there a two different situations:

1) in the derived class you define a method with the same name but
   different parameters. 

This is typically a serious bug in your program which can result in the 
exectution of the code of the wrong (not overloaded) function.


2) in the derived class you define not all overloaded variants. 

In that case the not overloaded variants are hidden but no run-time-error 
occurs. If you try to call a hidden variant, the compiler complains.


If "-Woverloaded-virtual" only triggers in case 1, it could be enabled
with "-Wall" as it typically indicates a severe bug in your program.

If there would be a "-Wpartial-overloaded-virtual" you could enable if you like 
it and you can. I have to work with a large existing code basis where I would 
not enable it.

I think to give different messages like ICC is the way to go.

Michael Cieslinski


-- 


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/20423] Warning -Woverloaded-virtual triggers to often
  2005-03-11 10:34 [Bug c++/20423] New: Warning -Woverloaded-virtual triggers to often micis at gmx dot de
  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
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-29 14:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-29 14:10 -------
*** Bug 20683 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |oliverst at online dot de


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-03-29 14:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-11 10:34 [Bug c++/20423] New: Warning -Woverloaded-virtual triggers to often micis at gmx dot de
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

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).