[PATCH] Fix PR c++/29573: ICE after parse error in template argument

Simon Martin simartin@users.sourceforge.net
Wed Jan 10 07:09:00 GMT 2007


Hi Mark.

> Anyhow, I think the right near-term fix here is to teach cp_tree_equal
> that, when recurring, MODIFY_EXPR has to be handled specially.  The
> second operand should only be compared for its code -- but should not be
> passed recursively to cp_tree_equal.
Didn't you mean MODOP_EXPRs instead of MODIFY_EXPRs? According to the remark 
about the "a += b" case in the section for MODIFY_EXPR in
    http://gcc.gnu.org/onlinedocs/gccint/Expression-trees.html#Expression-trees
("the representation for `i += 3' looks just like that for `i = i + 3'"), 
cp_tree_equal should already handle MODIFY_EXPRs for "a += b" properly.

The attached patch assumes that and just teaches cp_tree_equal to handle 
MODOP_EXPRs properly, which fixes the PR's testcase.

I've successfully regtested it on i686-pc-linux-gnu. Is it OK?

Thanks in advance,
Simon
-------------- next part --------------
2007-01-09  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/29573
	* tree.c (cp_tree_equal): Properly handle MODOP_EXPR trees.
-------------- next part --------------
Index: gcc/cp/tree.c
===================================================================
--- gcc/cp/tree.c	(revision 120620)
+++ gcc/cp/tree.c	(working copy)
@@ -1709,6 +1709,21 @@ cp_tree_equal (tree t1, tree t2)
 	  return cp_tree_equal (o1, o2);
       }
 
+    case MODOP_EXPR:
+      {
+	tree t1_op1, t2_op1;
+
+	if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
+	  return false;
+
+	t1_op1 = TREE_OPERAND (t1, 1);
+	t2_op1 = TREE_OPERAND (t2, 1);
+	if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1))
+	  return false;
+
+	return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2));
+      }
+
     case PTRMEM_CST:
       /* Two pointer-to-members are the same if they point to the same
 	 field or function in the same class.  */
-------------- next part --------------
2007-01-09  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/29573
	* g++.dg/template/sizeof-template-argument.C: New test.
-------------- next part --------------
/* This used to ICE (PR c++/29573) */
/* { dg-do "compile" } */

template<int> struct A {};

template<typename> struct B : A <sizeof(=)> {}; /* { dg-error "parse error in template argument list" } */

template<typename> struct C : A <sizeof(=)> {}; /* { dg-error "parse error in template argument list" } */

int a;

template<typename> struct D : A <sizeof(a=1)> {}; /* This used to ICE as well. */

template<typename> struct E : A <sizeof(a=1)> {}; /* This used to ICE as well. */



More information about the Gcc-patches mailing list