In this bug we were throwing away the explicit args when doing nested unification for a function, with the result that we didn't remember them when proceeding to do unification for the trailing arguments. Fixed by preserving ARGUMENT_PACK_EXPLICIT_ARGS.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 00e76793666566b604903930c77d4a644ec74a12
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Jun 17 16:35:57 2014 +0200

    	PR c++/61507
    	* pt.c (resolve_overloaded_unification): Preserve
    	ARGUMENT_PACK_EXPLICIT_ARGS.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d5cc257..f0a598b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -16838,7 +16838,16 @@ resolve_overloaded_unification (tree tparms,
       int i = TREE_VEC_LENGTH (targs);
       for (; i--; )
 	if (TREE_VEC_ELT (tempargs, i))
-	  TREE_VEC_ELT (targs, i) = TREE_VEC_ELT (tempargs, i);
+	  {
+	    tree old = TREE_VEC_ELT (targs, i);
+	    tree new_ = TREE_VEC_ELT (tempargs, i);
+	    if (new_ && old && ARGUMENT_PACK_P (old)
+		&& ARGUMENT_PACK_EXPLICIT_ARGS (old))
+	      /* Don't forget explicit template arguments in a pack.  */
+	      ARGUMENT_PACK_EXPLICIT_ARGS (new_)
+		= ARGUMENT_PACK_EXPLICIT_ARGS (old);
+	    TREE_VEC_ELT (targs, i) = new_;
+	  }
     }
   if (good)
     return true;
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic159.C b/gcc/testsuite/g++.dg/cpp0x/variadic159.C
new file mode 100644
index 0000000..2b14d30
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic159.C
@@ -0,0 +1,14 @@
+// PR c++/61507
+// { dg-do compile { target c++11 } }
+
+struct A {
+  void foo(const int &);
+  void foo(float);
+};
+
+template <typename... Args>
+void bar(void (A::*memfun)(Args...), Args... args);
+
+void go(const int& i) {
+  bar<const int &>(&A::foo, i);
+}

Reply via email to