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]

PATCH: nested class and template template parameter


Hi

The following patch fixes the nested class problem in my earlier
coerce_template_parms change.  It also works when current_class_type
is a local class.  

--Kriang

ChangeLog:

	* class.c (get_enclosing_class): New function.
	(is_base_of_enclosing_class): Likewise.
	* cp-tree.h (get_enclosing_class): Declare.
	(is_base_of_enclosing_class): Likewise.
	* pt.c (coerce_template_parms): Use them.

*** class.c	1998/07/21 17:23:44	2.0
--- class.c	1998/07/22 12:22:54
*************** is_empty_class (type)
*** 5579,5581 ****
--- 5579,5627 ----
      t = TREE_CHAIN (t);
    return (t == NULL_TREE);
  }
+ 
+ /* Find the enclosing class of the given NODE.  NODE can be a *_DECL or
+    a *_TYPE node.  NODE can also be a local class.  */
+ 
+ tree
+ get_enclosing_class (type)
+      tree type;
+ {
+   tree node = type;
+ 
+   while (node && TREE_CODE (node) != NAMESPACE_DECL)
+     {
+       switch (TREE_CODE_CLASS (TREE_CODE (node)))
+ 	{
+ 	case 'd':
+ 	  node = DECL_CONTEXT (node);
+ 	  break;
+ 
+ 	case 't':
+ 	  if (node != type)
+ 	    return node;
+ 	  node = TYPE_CONTEXT (node);
+ 	  break;
+ 
+ 	default:
+ 	  my_friendly_abort (0);
+ 	}
+     }
+   return NULL_TREE;
+ }
+ 
+ /* Return 1 if TYPE or one of its enclosing classes is derived from BASE.  */
+ 
+ int
+ is_base_of_enclosing_class (base, type)
+      tree base, type;
+ {
+   while (type)
+     {
+       if (get_binfo (base, type, 0))
+ 	return 1;
+ 
+       type = get_enclosing_class (type);
+     }
+   return 0;
+ }
*** cp-tree.h	1998/07/21 17:23:44	2.0
--- cp-tree.h	1998/07/22 12:25:57
*************** extern void maybe_push_cache_obstack		PR
*** 2320,2325 ****
--- 2320,2327 ----
  extern unsigned HOST_WIDE_INT skip_rtti_stuff	PROTO((tree *));
  extern tree build_self_reference		PROTO((void));
  extern void warn_hidden				PROTO((tree));
+ extern tree get_enclosing_class			PROTO((tree));
+ int is_base_of_enclosing_class			PROTO((tree, tree));
  
  /* in cvt.c */
  extern tree convert_to_reference		PROTO((tree, tree, int, int, tree));
*** pt.c	1998/07/21 17:23:44	2.0
--- pt.c	1998/07/22 12:24:56
*************** coerce_template_parms (parms, arglist, i
*** 2567,2575 ****
  		         && TREE_CODE (TYPE_NAME (arg)) == TYPE_DECL
  			 && DECL_ARTIFICIAL (TYPE_NAME (arg))
  			 && requires_tmpl_type
! 			 && current_class_type
! 			 /* FIXME what about nested types?  */
! 			 && get_binfo (arg, current_class_type, 0));
        if (is_tmpl_type && TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
  	arg = TYPE_STUB_DECL (arg);
        else if (is_tmpl_type && TREE_CODE (arg) == RECORD_TYPE)
--- 2567,2573 ----
  		         && TREE_CODE (TYPE_NAME (arg)) == TYPE_DECL
  			 && DECL_ARTIFICIAL (TYPE_NAME (arg))
  			 && requires_tmpl_type
! 			 && is_base_of_enclosing_class (arg, current_class_type));
        if (is_tmpl_type && TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM)
  	arg = TYPE_STUB_DECL (arg);
        else if (is_tmpl_type && TREE_CODE (arg) == RECORD_TYPE)



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