diff mbox

C++ PATCH for c++/60051 (ICE deducing array)

Message ID 53076907.9020903@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 21, 2014, 2:56 p.m. UTC
This patch benefits from the discussion of array deduction at last 
week's C++ standardization committee meeting, where we clarified that we 
should only try to deduce the array bound from an initializer-list if 
the array bound is deducible, i.e. if it's a non-type template 
parameter.  We also should avoid crashing on a 0-length init-list which 
would result in an invalid 0-length array.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 8fc69de2c377470b3ae9a8ebc65b0909d626d6e3
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 21 00:16:52 2014 -0500

    	DR 1591
    	PR c++/60051
    	* pt.c (unify): Only unify if deducible.  Handle 0-length list.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4cf387a..0f576a5 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -17262,14 +17262,16 @@  unify (tree tparms, tree targs, tree parm, tree arg, int strict,
 				   explain_p);
 	}
 
-      if (TREE_CODE (parm) == ARRAY_TYPE)
+      if (TREE_CODE (parm) == ARRAY_TYPE
+	  && deducible_array_bound (TYPE_DOMAIN (parm)))
 	{
 	  /* Also deduce from the length of the initializer list.  */
 	  tree max = size_int (CONSTRUCTOR_NELTS (arg));
 	  tree idx = compute_array_index_type (NULL_TREE, max, tf_none);
-	  if (TYPE_DOMAIN (parm) != NULL_TREE)
-	    return unify_array_domain (tparms, targs, TYPE_DOMAIN (parm),
-				       idx, explain_p);
+	  if (idx == error_mark_node)
+	    return unify_invalid (explain_p);
+	  return unify_array_domain (tparms, targs, TYPE_DOMAIN (parm),
+				     idx, explain_p);
 	}
 
       /* If the std::initializer_list<T> deduction worked, replace the
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist80.C b/gcc/testsuite/g++.dg/cpp0x/initlist80.C
new file mode 100644
index 0000000..7947f1f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist80.C
@@ -0,0 +1,6 @@ 
+// PR c++/60051
+// { dg-require-effective-target c++11 }
+
+#include <initializer_list>
+
+auto x[2] = {};			// { dg-error "" }