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]

C++ PATCH for array handling in templates



Here's a patch which fixes a crash on certain array declarations in
templates.

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1999-01-13  Mark Mitchell  <mark@markmitchell.com>

	* decl.c (grokdeclarator): Undo 1998-12-14 change.
	* tree.c (build_cplus_array_type_1): Likewise.
	* pt.c (instantiate_class_template): Remove misleading comment.
	(tsubst_aggr_type): Substitute if there are template parameters,
	regardless of whether or not they use template arguments.
	(unify): Likewise, but for unification.

Index: testsuite/g++.old-deja/g++.pt/crash25.C
===================================================================
RCS file: crash25.C
diff -N crash25.C
*** /dev/null	Sat Dec  5 20:30:03 1998
--- crash25.C	Wed Jan 13 14:32:00 1999
***************
*** 0 ****
--- 1,7 ----
+ // Build don't link:
+ 
+ template <class T>
+ void f()
+ {
+   int i[1 << 3];
+ }
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.291
diff -c -p -r1.291 decl.c
*** decl.c	1999/01/06 23:37:58	1.291
--- decl.c	1999/01/13 22:32:09
*************** grokdeclarator (declarator, declspecs, d
*** 9890,9898 ****
  		    && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
  		  size = TREE_OPERAND (size, 0);
  
! 		/* If this involves a template parameter, it'll be
! 		   constant, but we don't know what the value is yet.  */
! 		if (uses_template_parms (size))
  		  {
  		    /* Resolve a qualified reference to an enumerator or
  		       static const data member of ours.  */
--- 9890,9902 ----
  		    && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
  		  size = TREE_OPERAND (size, 0);
  
! 		/* If this involves a template parameter, it will be a
! 		   constant at instantiation time, but we don't know
! 		   what the value is yet.  Even if no template
! 		   parameters are involved, we may an expression that
! 		   is not a constant; we don't even simplify `1 + 2'
! 		   when processing a template.  */
! 		if (processing_template_decl)
  		  {
  		    /* Resolve a qualified reference to an enumerator or
  		       static const data member of ours.  */
Index: cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.249
diff -c -p -r1.249 pt.c
*** pt.c	1999/01/06 23:38:02	1.249
--- pt.c	1999/01/13 22:32:19
*************** instantiate_class_template (type)
*** 4475,4483 ****
           struct S<int> {};
  
         Now, the `S<U>' in `f<int>' is the specialization, not an
!        instantiation of the original template.  Mark the type as
!        complete, in the same way that we do for a definition of a
!        template class.  */
      goto end;
  
    /* Determine what specialization of the original template to
--- 4475,4481 ----
           struct S<int> {};
  
         Now, the `S<U>' in `f<int>' is the specialization, not an
!        instantiation of the original template.  */
      goto end;
  
    /* Determine what specialization of the original template to
*************** tsubst_aggr_type (t, args, in_decl, ente
*** 5043,5049 ****
        /* else fall through */
      case ENUMERAL_TYPE:
      case UNION_TYPE:
!       if (uses_template_parms (t))
  	{
  	  tree argvec;
  	  tree context;
--- 5041,5047 ----
        /* else fall through */
      case ENUMERAL_TYPE:
      case UNION_TYPE:
!       if (TYPE_TEMPLATE_INFO (t))
  	{
  	  tree argvec;
  	  tree context;
*************** unify (tparms, targs, parm, arg, strict,
*** 7671,7677 ****
        if (TREE_CODE (arg) != TREE_CODE (parm))
  	return 1;
    
!       if (CLASSTYPE_TEMPLATE_INFO (parm) && uses_template_parms (parm))
  	{
  	  tree t = NULL_TREE;
  	  if (strict & UNIFY_ALLOW_DERIVED)
--- 7669,7675 ----
        if (TREE_CODE (arg) != TREE_CODE (parm))
  	return 1;
    
!       if (CLASSTYPE_TEMPLATE_INFO (parm))
  	{
  	  tree t = NULL_TREE;
  	  if (strict & UNIFY_ALLOW_DERIVED)
Index: cp/tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.88
diff -c -p -r1.88 tree.c
*** tree.c	1999/01/06 20:57:35	1.88
--- tree.c	1999/01/13 22:32:20
*************** build_cplus_array_type_1 (elt_type, inde
*** 416,423 ****
        saveable_obstack = &permanent_obstack;
      }
  
!   if (uses_template_parms (elt_type)
!       || uses_template_parms (index_type))
      {
        t = make_node (ARRAY_TYPE);
        TREE_TYPE (t) = elt_type;
--- 416,422 ----
        saveable_obstack = &permanent_obstack;
      }
  
!   if (processing_template_decl)
      {
        t = make_node (ARRAY_TYPE);
        TREE_TYPE (t) = elt_type;


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