diff mbox

[C++] Fix ICE with invalid static data member (PR c++/51430)

Message ID 20111206121627.GQ27242@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Dec. 6, 2011, 12:16 p.m. UTC
Hi!

On this invalid testcase we ICE starting with PR47956 changes, because
a static data member is VAR_HAD_UNKNOWN_BOUND, but
maybe_deduce_size_from_array_init changes its type from incomplete
array to error_mark_node.  tsubst_decl assumes that VAR_HAD_UNKNOWN_BOUND
has ARRAY_TYPE type.  Here is one possible fix, another possible fix
would be to add if (type == error_mark_node) return type;
to the beginning of strip_array_domain, another option perhaps adjust
the SET_VAR_HAD_UNKNOWN_BOUND macro to take another argument and
be able to clear that flag and clear it in
maybe_deduce_size_from_array_init.

This variant has been bootstrapped/regtested on x86_64-linux and i686-linux.

2011-12-06  Jakub Jelinek  <jakub@redhat.com>

	PR c++/51430
	* pt.c (tsubst_decl): Don't call strip_array_domain on
	error_mark_node.


	Jakub

Comments

Jason Merrill Dec. 6, 2011, 7:41 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

--- gcc/cp/pt.c.jj	2011-12-01 11:45:04.000000000 +0100
+++ gcc/cp/pt.c	2011-12-06 09:11:29.715888859 +0100
@@ -10622,7 +10622,9 @@  tsubst_decl (tree t, tree args, tsubst_f
 	      type = DECL_ORIGINAL_TYPE (t);
 	    else
 	      type = TREE_TYPE (t);
-	    if (TREE_CODE (t) == VAR_DECL && VAR_HAD_UNKNOWN_BOUND (t))
+	    if (TREE_CODE (t) == VAR_DECL
+		&& VAR_HAD_UNKNOWN_BOUND (t)
+		&& type != error_mark_node)
 	      type = strip_array_domain (type);
 	    type = tsubst (type, args, complain, in_decl);
 	  }
--- gcc/testsuite/g++.dg/template/static32.C.jj	2011-12-06 09:16:02.606219171 +0100
+++ gcc/testsuite/g++.dg/template/static32.C	2011-12-06 09:16:28.001068818 +0100
@@ -0,0 +1,9 @@ 
+// PR c++/51430
+// { dg-do compile }
+
+template<int> struct A
+{
+  static const int x[] = 0;	// { dg-error "in-class initialization|initializer fails" }
+};
+
+A<0> a;