This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/20423] Warning -Woverloaded-virtual triggers to often



------- Comment #6 from manu at gcc dot gnu dot org  2007-02-16 10:01 -------
A really wild-guess patch. Comments?


Index: gcc/cp/class.c
===================================================================
--- gcc/cp/class.c      (revision 121953)
+++ gcc/cp/class.c      (working copy)
@@ -2377,6 +2377,8 @@ warn_hidden (tree t)
       tree binfo;
       int j;

+      bool just_hidden = false;
+
       /* All functions in this slot in the CLASSTYPE_METHOD_VEC will
         have the same name.  Figure out what name that is.  */
       name = DECL_NAME (OVL_CURRENT (fns));
@@ -2408,8 +2410,14 @@ warn_hidden (tree t)
                /* If the method from the base class has the same
                   signature as the method from the derived class, it
                   has been overridden.  */
-               if (same_signature_p (fndecl, TREE_VALUE (*prev)))
-                 *prev = TREE_CHAIN (*prev);
+               if (same_signature_p (fndecl, TREE_VALUE (*prev)))
+                 {
+                   *prev = TREE_CHAIN (*prev);
+                   /* If at least one method has the same signature,
+                      the not overloaded variants are just
+                      hidden.  */
+                   just_hidden = true;
+                 }
                else
                  prev = &TREE_CHAIN (*prev);
            }
@@ -2419,9 +2427,17 @@ warn_hidden (tree t)
         as they are hidden.  */
       while (base_fndecls)
        {
-         /* Here we know it is a hider, and no overrider exists.  */
-         warning (0, "%q+D was hidden", TREE_VALUE (base_fndecls));
-         warning (0, "  by %q+D", fns);
+         /* If Here we know it is a hider, and no overrider exists.  */
+         if (just_hidden)
+           {
+             warning (OPT_Wpartial_overloaded_virtual, "%q+D was hidden",
TREE_VALUE (base_fndecls));
+             warning (OPT_Wpartial_overloaded_virtual, "  by %q+D", fns);
+           }                                                                   
+         else
+           {
+             warning (OPT_Woverloaded_virtual, "%q+D was hidden", TREE_VALUE
(base_fndecls));
+             warning (OPT_Woverloaded_virtual, "  by %q+D", fns);
+           }
          base_fndecls = TREE_CHAIN (base_fndecls);
        }
     }


-- 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]