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: ICE announcing template function


Hi,
Here's a patch for http://egcs.cygnus.com/ml/egcs-bugs/1999-03/msg00984.html
which turned out to be an ICE when announcing a function. I distilled the test
case down to that which I've attached. What was happening that the default
argument to B<T>::B contains an indirection, dump_expr looks inside this to see
if it's really a reference, but at that point, the type is NULL, because it's a
pointer to a templatized type.

I fixed it in dump_expr by checking that TREE_TYPE is non-null before looking
into it. With this patch applied, Julian's code gives a pile of syntax errors
later on, which I've not examined.

Enjoy,

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
egcs/gcc/cp/ChangeLog:
Fri Apr  9 18:01:31 BST 1999  Nathan Sidwell  <nathan@acm.org>

	* error.c (dump_expr): Don't die printing a template expression.

Index: egcs/gcc/cp/error.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/error.c,v
retrieving revision 1.71
diff -c -3 -p -r1.71 error.c
*** error.c	1999/04/02 15:36:13	1.71
--- error.c	1999/04/09 17:00:41
*************** dump_expr (t, nop)
*** 1563,1571 ****
  	}
        else
  	{
! 	  if (TREE_OPERAND (t,0) != NULL_TREE
! 	      && NEXT_CODE (TREE_OPERAND (t, 0)) == REFERENCE_TYPE)
! 	    dump_expr (TREE_OPERAND (t, 0), nop);
  	  else
  	    dump_unary_op ("*", t, nop);
  	}
--- 1563,1573 ----
  	}
        else
  	{
! 	  tree op = TREE_OPERAND (t,0);
! 	  
! 	  if (op != NULL_TREE && TREE_TYPE (op)
! 	      && NEXT_CODE (op) == REFERENCE_TYPE)
! 	    dump_expr (op, nop);
  	  else
  	    dump_unary_op ("*", t, nop);
  	}
// Build don't link:

// Copyright (C) 1999 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 9 Apr 1999 <nathan@acm.org>
// derrived from bug report from Julian Payne" <payne@ilog.fr>

// check we don't die announcing a template fn with template default arg

template <class T>
struct A
{
  A();
};

template <class T>
struct B
{
  typedef A<T> I;
  
  B(I &t = (*new I()));
};

template <class T>
B<T>::B(I &t) // ICE was here
{
  
}

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