This is the mail archive of the gcc-patches@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]

C++ PATCH: PR 9791


This patch fixes a warning regression; tested on i686-pc-linux-gnu,
applied on the mainline and the branch.

(It also should make -Woverloaded-virtual a tad faster by avoiding a
linear search of all of the function in base classes; it instead uses
lookup_fnfields_1 to access the cached table of functions.)

--
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery dot com

2003-03-06  Mark Mitchell  <mark at codesourcery dot com>

	PR c++/9791
	* class.c (get_basefndecls): Use lookup_fnfields_1.

2003-03-06  Mark Mitchell  <mark at codesourcery dot com>

	PR c++/9791
	* g++.dg/warn/Woverloaded-1.C: New test.

Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.525
diff -c -5 -p -r1.525 class.c
*** cp/class.c	5 Mar 2003 08:27:42 -0000	1.525
--- cp/class.c	6 Mar 2003 20:02:56 -0000
*************** get_basefndecls (tree name, tree t)
*** 2522,2536 ****
    tree methods;
    tree base_fndecls = NULL_TREE;
    int n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
    int i;
  
!   for (methods = TYPE_METHODS (t); methods; methods = TREE_CHAIN (methods))
!     if (TREE_CODE (methods) == FUNCTION_DECL
! 	&& DECL_VINDEX (methods) != NULL_TREE
! 	&& DECL_NAME (methods) == name)
!       base_fndecls = tree_cons (NULL_TREE, methods, base_fndecls);
  
    if (base_fndecls)
      return base_fndecls;
  
    for (i = 0; i < n_baseclasses; i++)
--- 2522,2544 ----
    tree methods;
    tree base_fndecls = NULL_TREE;
    int n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
    int i;
  
!   /* Find virtual functions in T with the indicated NAME.  */
!   i = lookup_fnfields_1 (t, name);
!   if (i != -1)
!     for (methods = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), i);
! 	 methods;
! 	 methods = OVL_NEXT (methods))
!       {
! 	tree method = OVL_CURRENT (methods);
! 
! 	if (TREE_CODE (method) == FUNCTION_DECL
! 	    && DECL_VINDEX (method))
! 	  base_fndecls = tree_cons (NULL_TREE, method, base_fndecls);
!       }
  
    if (base_fndecls)
      return base_fndecls;
  
    for (i = 0; i < n_baseclasses; i++)
Index: testsuite/g++.dg/warn/Woverloaded-1.C
===================================================================
RCS file: testsuite/g++.dg/warn/Woverloaded-1.C
diff -N testsuite/g++.dg/warn/Woverloaded-1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/warn/Woverloaded-1.C	6 Mar 2003 20:04:09 -0000
***************
*** 0 ****
--- 1,17 ----
+ /* { dg-options "-Woverloaded-virtual" } */
+ 
+ class Base {
+ public:
+   virtual ~Base() {
+   }
+ };
+ 
+ class Derived: public Base {
+ public:
+   int Base() { // There should be no error here.
+     return 5;
+   }
+ };
+ 
+ int main() {
+ }


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