diff mbox

C++ PATCH for c++/64520 (ICE with std::initializer_list<T...>)

Message ID 54B5831D.3030801@redhat.com
State New
Headers show

Commit Message

Jason Merrill Jan. 13, 2015, 8:42 p.m. UTC
The special rules for deduction of std::initializer_list don't support a 
pack expansion, but we shouldn't crash.

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

Patch

commit a1607c38aaf6e04c2a601ee78dca67984e179986
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jan 12 13:27:20 2015 -0500

    	PR c++/64520
    	* pt.c (unify): Don't try to deduce to std::initializer_list<T...>.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d8652fb..3ac93db 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -17854,7 +17854,13 @@  unify (tree tparms, tree targs, tree parm, tree arg, int strict,
       if (TREE_CODE (parm) == ARRAY_TYPE)
 	elttype = TREE_TYPE (parm);
       else
-	elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (parm), 0);
+	{
+	  elttype = TREE_VEC_ELT (CLASSTYPE_TI_ARGS (parm), 0);
+	  /* Deduction is defined in terms of a single type, so just punt
+	     on the (bizarre) std::initializer_list<T...>.  */
+	  if (PACK_EXPANSION_P (elttype))
+	    return unify_success (explain_p);
+	}
 
       FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (arg), i, elt)
 	{
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist91.C b/gcc/testsuite/g++.dg/cpp0x/initlist91.C
new file mode 100644
index 0000000..1387557
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist91.C
@@ -0,0 +1,8 @@ 
+// PR c++/64520
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+struct A {
+  template <typename... B> A(std::initializer_list<B...>);
+};
+A a { 0 };			// { dg-error "" }