This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c++/28711: ICE on invalid initializer for multidimensional array
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 14 Aug 2006 23:48:04 +0200 (CEST)
- Subject: [patch] Fix PR c++/28711: ICE on invalid initializer for multidimensional array
The following invalid code snippet triggers an ICE in the C++ frontend:
template<int> struct A
{
int x[1][1];
A() : x((int[1][]){{0}}) {}
};
A<0> a;
bug.cc: In constructor 'A<<anonymous> >::A()':
bug.cc:4: error: multidimensional array must have bounds for all dimensions except the first
bug.cc: In constructor 'A<<anonymous> >::A() [with int <anonymous> = 0]':
bug.cc:7: instantiated from here
bug.cc:4: internal compiler error: tree check: expected class 'type', have 'exceptional' (error_mark) in tsubst_copy_and_build, at cp/pt.c:9196
Please submit a full bug report, [etc.]
Inside tsubst_copy_and_build the compiler calls tsubst, but does not
check the return value for errors. The patch below fixes that by
an appropriate check.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?
Regards,
Volker
:ADDPATCH C++:
2006-08-14 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28711
* pt.c (tsubst_copy_and_build) <case CONSTRUCTOR>: Robustify.
===================================================================
--- gcc/gcc/cp/pt.c 2006-08-14 10:53:44 +0200
+++ gcc/gcc/cp/pt.c 2006-08-14 10:49:53 +0200
@@ -9075,6 +9075,9 @@ tsubst_copy_and_build (tree t,
tree type = tsubst (TREE_TYPE (t), args, complain, in_decl);
bool process_index_p;
+ if (type == error_mark_node)
+ return error_mark_node;
+
/* digest_init will do the wrong thing if we let it. */
if (type && TYPE_PTRMEMFUNC_P (type))
return t;
===================================================================
2006-08-14 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28711
* g++.dg/template/ctor8.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/ctor8.C 2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/template/ctor8.C 2006-08-14 10:58:12 +0200
@@ -0,0 +1,11 @@
+// PR c++/28711
+// { dg-do compile }
+// { dg-options "" }
+
+template<int> struct A
+{
+ int x[1][1];
+ A() : x((int[1][]){{0}}) {} // { dg-error "except the first" }
+};
+
+A<0> a;
===================================================================