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++] Fix 19270


Hi,
this patch fixes 19270, a backend ICE caused by incorrect template
instantiation.  Firstly tsubst_copy forgot that ARRAY_REF has two optional
trailing parameters, but more imporantly there was some now obsolete
code in tsubst_copy_and_build.  We used to represent 'new T[expr]' as
a VEC_NEW containing an ARRAY_REF, and that's what was blowing up now.
Fortunately we don't do that for a VEC_NEW anymore, so the code
can go away.

booted & tested on i686-pc-linux-gnu.

nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2005-01-06  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/19270
	* pt.c (tsubst_copy) <ARRAY_REF case>: Handle separately.
	(tsubst_copy_and_build) <ARRAY_REF case>: Remove obsolete
	array-new handling code.  Use build_x_binary_op.

Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.963
diff -c -3 -p -r1.963 pt.c
*** cp/pt.c	5 Jan 2005 10:02:21 -0000	1.963
--- cp/pt.c	6 Jan 2005 12:39:40 -0000
*************** tsubst_copy (tree t, tree args, tsubst_f
*** 7869,7875 ****
      case GE_EXPR:
      case LT_EXPR:
      case GT_EXPR:
-     case ARRAY_REF:
      case COMPOUND_EXPR:
      case SCOPE_REF:
      case DOTSTAR_EXPR:
--- 7869,7874 ----
*************** tsubst_copy (tree t, tree args, tsubst_f
*** 7882,7887 ****
--- 7881,7893 ----
  	(code, tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl),
  	 tsubst_copy (TREE_OPERAND (t, 1), args, complain, in_decl));
  
+     case ARRAY_REF:
+       return build_nt
+ 	(ARRAY_REF,
+ 	 tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl),
+ 	 tsubst_copy (TREE_OPERAND (t, 1), args, complain, in_decl),
+ 	 NULL_TREE, NULL_TREE);
+ 
      case CALL_EXPR:
        return build_nt (code, 
  		       tsubst_copy (TREE_OPERAND (t, 0), args,
*************** tsubst_copy_and_build (tree t, 
*** 8526,8546 ****
      case SCOPE_REF:
        return tsubst_qualified_id (t, args, complain, in_decl, /*done=*/true,
  				  /*address_p=*/false);
- 
      case ARRAY_REF:
-       if (tsubst_copy (TREE_OPERAND (t, 0), args, complain, in_decl)
- 	  == NULL_TREE)
- 	/* new-type-id */
- 	return build_nt (ARRAY_REF, NULL_TREE, RECUR (TREE_OPERAND (t, 1)),
- 			 NULL_TREE, NULL_TREE);
- 
        op1 = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0),
  						args, complain, in_decl);
!       /* Remember that there was a reference to this entity.  */
!       if (DECL_P (op1))
! 	mark_used (op1);
!       return grok_array_decl (op1, RECUR (TREE_OPERAND (t, 1)));
! 
      case SIZEOF_EXPR:
      case ALIGNOF_EXPR:
        op1 = TREE_OPERAND (t, 0);
--- 8532,8543 ----
      case SCOPE_REF:
        return tsubst_qualified_id (t, args, complain, in_decl, /*done=*/true,
  				  /*address_p=*/false);
      case ARRAY_REF:
        op1 = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0),
  						args, complain, in_decl);
!       return build_x_binary_op (ARRAY_REF, op1, RECUR (TREE_OPERAND (t, 1)),
! 				/*overloaded_p=*/NULL);
!       
      case SIZEOF_EXPR:
      case ALIGNOF_EXPR:
        op1 = TREE_OPERAND (t, 0);
// Copyright (C) 2005 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 5 Jan 2005 <nathan@codesourcery.com>

// PR 19270: ICE
// Origin:  Ralf Wildenhues <Ralf.Wildenhues@gmx.de>

template<class T> struct Vec {
  T* data;
  T& operator[](int i) const;
};

template<class T> inline T& Vec<T>::operator[](int i) const
{
  return (&data[0])[i];
}

inline double foo(Vec<double> v)
{
  return v[0];
}

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