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]

[PATCH] Fix C++/29002, ICE with invalid (unknown size) array of ptr-to-member


The problem here is that we have an assert if the max_index is a non
INTEGER_CST but we have an error mark here because the size is unknown
which we will error out later on.  Since for ptr-to-member functions we
need to initialize the variables to -1 instead of 0, we need to loop
through the array initializing those parts to -1.  And since we don't
know the size, we will get an error mark and then we crash.  Adding a
check for error_mark_node, we get passed the ICE and get an error
message later on from the normal progressing of the decl.

OK? Bootstrapped and tested on i686-linux-gnu with no regressions.

:ADDPATCH C++:

Thanks,
Andrew Pinski

cp/ChangeLog:
	* init.c (build_zero_init): If we have an error mark node for
	the array size, return.

testsuite/ChangeLog:
	* g++.dg/init/array22.C: New test.
	* g++.dg/init/array23.C: New test.
Index: testsuite/g++.dg/init/array22.C
===================================================================
--- testsuite/g++.dg/init/array22.C	(revision 0)
+++ testsuite/g++.dg/init/array22.C	(revision 0)
@@ -0,0 +1,6 @@
+// PR C++/29002
+// We ICE trying to set the "zero" initializer on the incomplete
+//  array
+
+struct A {};
+int A::* x[]; // { dg-error "size" }
Index: testsuite/g++.dg/init/array23.C
===================================================================
--- testsuite/g++.dg/init/array23.C	(revision 0)
+++ testsuite/g++.dg/init/array23.C	(revision 0)
@@ -0,0 +1,6 @@
+// PR C++/29002
+// We ICE trying to set the "zero" initializer on the incomplete
+//  array
+
+struct A {A();int A::* t;};
+A x[]; // { dg-error "size" }
Index: cp/init.c
===================================================================
--- cp/init.c	(revision 116814)
+++ cp/init.c	(working copy)
@@ -223,6 +223,10 @@ build_zero_init (tree type, tree nelts, 
 				 nelts, integer_one_node);
       else
 	max_index = array_type_nelts (type);
+      /* If we have an error_mark here, we should just return NULL as we don't
+	 know the size of the array yet.  */
+      if (max_index == error_mark_node)
+	return NULL_TREE;
       gcc_assert (TREE_CODE (max_index) == INTEGER_CST);
 
       /* A zero-sized array, which is accepted as an extension, will

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