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: Fix PR 11789


This patch fixes PR 11789, a 3.4 regression.

When looking for bases in member-initializers, we need to ignore the
ambiguity of the base class.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-08-10  Mark Mitchell  <mark@codesourcery.com>

	PR c++/11789
	* cp-tree.h (get_vbase): Remove.
	(get_vbase_types): Remove.
	* init.c (expand_member_init): Correct logic for looking up base
	classes.

2003-08-10  Mark Mitchell  <mark@codesourcery.com>

	PR c++/11789.C
	* g++.dg/inherit/multiple1.C: New test.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.899
diff -c -5 -p -r1.899 cp-tree.h
*** cp/cp-tree.h	10 Aug 2003 15:10:34 -0000	1.899
--- cp/cp-tree.h	11 Aug 2003 02:46:30 -0000
*************** extern bool emit_tinfo_decl (tree);
*** 4016,4036 ****
  
  /* in search.c */
  extern bool accessible_base_p (tree, tree);
  extern tree lookup_base (tree, tree, base_access, base_kind *);
  extern int types_overlap_p			(tree, tree);
- extern tree get_vbase				(tree, tree);
  extern tree get_dynamic_cast_base_type          (tree, tree);
  extern int accessible_p                         (tree, tree);
  extern tree lookup_field_1                      (tree, tree, bool);
  extern tree lookup_field			(tree, tree, int, bool);
  extern int lookup_fnfields_1                    (tree, tree);
  extern tree lookup_fnfields			(tree, tree, int);
  extern tree lookup_member			(tree, tree, int, bool);
  extern int look_for_overrides			(tree, tree);
  extern void get_pure_virtuals		        (tree);
- extern void get_vbase_types			(tree);
  extern void maybe_suppress_debug_info		(tree);
  extern void note_debug_info_needed		(tree);
  extern void push_class_decls			(tree);
  extern void pop_class_decls			(void);
  extern void unuse_fields			(tree);
--- 4016,4034 ----
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.336
diff -c -5 -p -r1.336 init.c
*** cp/init.c	28 Jul 2003 11:06:30 -0000	1.336
--- cp/init.c	11 Aug 2003 02:46:31 -0000
*************** expand_member_init (tree name)
*** 961,990 ****
    else
      basetype = NULL_TREE;
  
    if (basetype)
      {
!       tree binfo;
  
        if (current_template_parms)
  	return basetype;
  
!       binfo = lookup_base (current_class_type, basetype, 
! 			   ba_ignore, NULL);
!       if (!binfo || (!TREE_VIA_VIRTUAL (binfo)
! 		     && (BINFO_INHERITANCE_CHAIN (binfo)
! 			 != TYPE_BINFO (current_class_type))))
  	{
  	  if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  	    error ("type `%D' is not a direct or virtual base of `%T'",
  		   name, current_class_type);
  	  else
  	    error ("type `%D' is not a direct base of `%T'",
  		   name, current_class_type);
  	  return NULL_TREE;
  	}
!       return binfo;
      }
    else
      {
        if (TREE_CODE (name) == IDENTIFIER_NODE)
  	field = lookup_field (current_class_type, name, 1, false);
--- 961,1025 ----
    else
      basetype = NULL_TREE;
  
    if (basetype)
      {
!       tree class_binfo;
!       tree direct_binfo;
!       tree virtual_binfo;
!       int i;
  
        if (current_template_parms)
  	return basetype;
  
!       class_binfo = TYPE_BINFO (current_class_type);
!       direct_binfo = NULL_TREE;
!       virtual_binfo = NULL_TREE;
! 
!       /* Look for a direct base.  */
!       for (i = 0; i < BINFO_N_BASETYPES (class_binfo); ++i)
! 	if (same_type_p (basetype, 
! 			 TYPE_BINFO_BASETYPE (current_class_type, i)))
! 	  {
! 	    direct_binfo = BINFO_BASETYPE (class_binfo, i);
! 	    break;
! 	  }
!       /* Look for a virtual base -- unless the direct base is itself
! 	 virtual.  */
!       if (!direct_binfo || !TREE_VIA_VIRTUAL (direct_binfo))
! 	{
! 	  virtual_binfo 
! 	    = purpose_member (basetype,
! 			      CLASSTYPE_VBASECLASSES (current_class_type));
! 	  if (virtual_binfo)
! 	    virtual_binfo = TREE_VALUE (virtual_binfo);
! 	}
! 
!       /* [class.base.init]
! 	 
!          If a mem-initializer-id is ambiguous because it designates
! 	 both a direct non-virtual base class and an inherited virtual
! 	 base class, the mem-initializer is ill-formed.  */
!       if (direct_binfo && virtual_binfo)
! 	{
! 	  error ("'%D' is both a direct base and an indirect virtual base",
! 		 basetype);
! 	  return NULL_TREE;
! 	}
! 
!       if (!direct_binfo && !virtual_binfo)
  	{
  	  if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  	    error ("type `%D' is not a direct or virtual base of `%T'",
  		   name, current_class_type);
  	  else
  	    error ("type `%D' is not a direct base of `%T'",
  		   name, current_class_type);
  	  return NULL_TREE;
  	}
! 
!       return direct_binfo ? direct_binfo : virtual_binfo;
      }
    else
      {
        if (TREE_CODE (name) == IDENTIFIER_NODE)
  	field = lookup_field (current_class_type, name, 1, false);
Index: testsuite/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/ChangeLog,v
retrieving revision 1.2964
diff -c -5 -p -r1.2964 ChangeLog
*** testsuite/ChangeLog	10 Aug 2003 15:17:35 -0000	1.2964
--- testsuite/ChangeLog	11 Aug 2003 02:46:31 -0000
***************
*** 1,5 ****
--- 1,10 ----
+ 2003-08-10  Mark Mitchell  <mark@codesourcery.com>
+ 
+ 	PR c++/11789.C
+ 	* g++.dg/inherit/multiple1.C: New test.
+ 
  2003-08-10  Nathan Sidwell  <nathan@codesourcery.com>
  
  	* gcc.dg/spe1.c: New test.
  
  	PR c++/11670
Index: testsuite/g++.dg/inherit/multiple1.C
===================================================================
RCS file: testsuite/g++.dg/inherit/multiple1.C
diff -N testsuite/g++.dg/inherit/multiple1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/inherit/multiple1.C	11 Aug 2003 02:46:31 -0000
***************
*** 0 ****
--- 1,20 ----
+ // { dg-options "-w" }
+ 
+ struct Base {
+   int b;
+   
+   Base(int b) : b(b) { }
+ };
+ 
+ struct Derived : public Base {
+   Derived(int d) : Base(d) { }
+ };
+ 
+ struct Final : public Derived, public Base {
+   Final(int f) : Derived(f), Base(f-1) { }
+ };
+ 
+ int main()
+ {
+   Final f(5);
+ }


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