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] PR 34397


Hi,

this is for a P2 regression. The fix follows rather naturally from the
discussion in the audit trail: basically call build_new_op and
build_min_non_dep in the way appropriate for an ARRAY_REF.

Tested x86_64-linux. Ok for mainline?

Paolo.

//////////////////
/cp
2009-02-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/34397
	* typeck.c (build_x_array_ref): New.
	* cp-tree.h: Declare it.
	* pt.c (tsubst_copy_and_build): Use it for case ARRAY_REF.

/testsuite
2009-02-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/34397
	* g++.dg/template/crash88.C: New.
	* g++.dg/template/crash89.C: Likewise.
Index: testsuite/g++.dg/template/crash88.C
===================================================================
*** testsuite/g++.dg/template/crash88.C	(revision 0)
--- testsuite/g++.dg/template/crash88.C	(revision 0)
***************
*** 0 ****
--- 1,6 ----
+ // PR c++/34397
+ 
+ template<typename T, int = T()[0]> struct A
+ {
+   typedef A<T> B;
+ };
Index: testsuite/g++.dg/template/crash89.C
===================================================================
*** testsuite/g++.dg/template/crash89.C	(revision 0)
--- testsuite/g++.dg/template/crash89.C	(revision 0)
***************
*** 0 ****
--- 1,8 ----
+ // PR c++/34397
+ 
+ template<typename T, int = T()[0]> struct A
+ {
+   typedef A<T> B;
+ };
+ 
+ A<int> a; // { dg-error "subscripted|template|declaration" }
Index: cp/typeck.c
===================================================================
*** cp/typeck.c	(revision 144062)
--- cp/typeck.c	(working copy)
*************** build_x_binary_op (enum tree_code code,
*** 3198,3203 ****
--- 3198,3231 ----
    return expr;
  }
  
+ /* Build and return an ARRAY_REF expression.  */
+ 
+ tree
+ build_x_array_ref (tree arg1, tree arg2, tsubst_flags_t complain)
+ {
+   tree orig_arg1 = arg1;
+   tree orig_arg2 = arg2;
+   tree expr;
+ 
+   if (processing_template_decl)
+     {
+       if (type_dependent_expression_p (arg1)
+ 	  || type_dependent_expression_p (arg2))
+ 	return build_min_nt (ARRAY_REF, arg1, arg2,
+ 			     NULL_TREE, NULL_TREE);
+       arg1 = build_non_dependent_expr (arg1);
+       arg2 = build_non_dependent_expr (arg2);
+     }
+ 
+   expr = build_new_op (ARRAY_REF, LOOKUP_NORMAL, arg1, arg2, NULL_TREE,
+ 		       /*overloaded_p=*/NULL, complain);
+ 
+   if (processing_template_decl && expr != error_mark_node)
+     return build_min_non_dep (ARRAY_REF, expr, orig_arg1, orig_arg2,
+ 			      NULL_TREE, NULL_TREE);
+   return expr;
+ }
+ 
  /* For the c-common bits.  */
  tree
  build_binary_op (location_t location, enum tree_code code, tree op0, tree op1,
Index: cp/cp-tree.h
===================================================================
*** cp/cp-tree.h	(revision 144062)
--- cp/cp-tree.h	(working copy)
*************** extern tree build_x_binary_op			(enum tr
*** 4937,4942 ****
--- 4937,4943 ----
  						 enum tree_code, tree,
  						 enum tree_code, bool *,
  						 tsubst_flags_t);
+ extern tree build_x_array_ref			(tree, tree, tsubst_flags_t);
  extern tree build_x_unary_op			(enum tree_code, tree,
                                                   tsubst_flags_t);
  extern tree cp_build_unary_op                   (enum tree_code, tree, int, 
Index: cp/pt.c
===================================================================
*** cp/pt.c	(revision 144062)
--- cp/pt.c	(working copy)
***************
*** 1,6 ****
  /* Handle parameterized types (templates) for GNU C++.
     Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
!    2001, 2002, 2003, 2004, 2005, 2007, 2008  Free Software Foundation, Inc.
     Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
     Rewritten by Jason Merrill (jason@cygnus.com).
  
--- 1,7 ----
  /* Handle parameterized types (templates) for GNU C++.
     Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
!    2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
!    Free Software Foundation, Inc.
     Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
     Rewritten by Jason Merrill (jason@cygnus.com).
  
*************** tsubst_copy_and_build (tree t,
*** 11228,11243 ****
      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,
! 				(TREE_NO_WARNING (TREE_OPERAND (t, 0))
! 				 ? ERROR_MARK
! 				 : TREE_CODE (TREE_OPERAND (t, 0))),
! 				RECUR (TREE_OPERAND (t, 1)),
! 				(TREE_NO_WARNING (TREE_OPERAND (t, 1))
! 				 ? ERROR_MARK
! 				 : TREE_CODE (TREE_OPERAND (t, 1))),
! 				/*overloaded_p=*/NULL,
! 				complain);
  
      case SIZEOF_EXPR:
        if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))
--- 11229,11235 ----
      case ARRAY_REF:
        op1 = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0),
  						args, complain, in_decl);
!       return build_x_array_ref (op1, RECUR (TREE_OPERAND (t, 1)), complain);
  
      case SIZEOF_EXPR:
        if (PACK_EXPANSION_P (TREE_OPERAND (t, 0)))

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