[patch, c++] Patch for PR c++/37646

Steve Ellcey sje@cup.hp.com
Thu Dec 11 22:18:00 GMT 2008


Here is a patch for PR c++/37646.  I changed instantiate_type to allow
for COND_EXPR in much the same way we handle COMPOUND_EXPR.  This fixes
the reported bug and caused no regressions when tested on IA64 HP-UX
and Linux.

OK for checkin?

Steve Ellcey
sje@cup.hp.com


2008-12-11  Steve Ellcey  <sje@cup.hp.com>

	 PR c++/37646
	* class.c (instantiate_type): Allow COND_EXPR.


2008-12-11  Steve Ellcey  <sje@cup.hp.com>

	PR c++/37646
	* g++.dg/other/crash-5.C: New test.


Index: class.c
===================================================================
--- class.c	(revision 142693)
+++ class.c	(working copy)
@@ -6283,6 +6283,7 @@ instantiate_type (tree lhstype, tree rhs
   gcc_assert (TREE_CODE (rhs) == ADDR_EXPR
 	      || TREE_CODE (rhs) == COMPONENT_REF
 	      || TREE_CODE (rhs) == COMPOUND_EXPR
+	      || TREE_CODE (rhs) == COND_EXPR
 	      || really_overloaded_fn (rhs));
 
   /* We don't overwrite rhs if it is an overloaded function.
@@ -6353,6 +6354,19 @@ instantiate_type (tree lhstype, tree rhs
       TREE_TYPE (rhs) = lhstype;
       return rhs;
 
+    case COND_EXPR:
+      TREE_OPERAND (rhs, 1)
+	= instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
+      if (TREE_OPERAND (rhs, 1) == error_mark_node)
+	return error_mark_node;
+      TREE_OPERAND (rhs, 2)
+	= instantiate_type (lhstype, TREE_OPERAND (rhs, 2), flags);
+      if (TREE_OPERAND (rhs, 2) == error_mark_node)
+	return error_mark_node;
+
+      TREE_TYPE (rhs) = lhstype;
+      return rhs;
+
     case ADDR_EXPR:
     {
       if (PTRMEM_OK_P (rhs))


Index: g++.dg/other/crash-5.C
===================================================================
--- g++.dg/other/crash-5.C	(revision 0)
+++ g++.dg/other/crash-5.C	(revision 0)
@@ -0,0 +1,12 @@
+// Origin: PR c++/37646
+// { dg-do compile }
+
+struct A
+{
+  void foo();
+
+  void bar(int i)
+  {
+    void (*p)() = i ? foo : foo; // { dg-error "does not match" }
+  }
+};



More information about the Gcc-patches mailing list