Patch c++/40155
Dodji Seketeli
dodji@redhat.com
Wed Jan 6 10:12:00 GMT 2010
On Tue, Jan 05, 2010 at 10:15:00AM -0500, Jason Merrill wrote:
> I think it would be clearer to move the
> template_parm_level_and_index call out from the various if/elses
> into the main body of the loop and then just copy the TMPL_ARG =
> from the final else.
I have updated the patch below, hopefully accordingly.
Tested on x86_64-unknown-linux-gnu.
> >This bug does not seem to be a regression, but as it's an
> >'accept-invalid' on c++0x (should I say c++1x now?), maybe the final fix
> >could go into 4.5?
>
> Rather, it's a rejects-valid.
Indeed.
> We're going to keep calling it c++0x until we have an actual date.
Okay.
> Yes, the fix can go into 4.5 since it only affects C++0x.
Thanks.
Dodji
commit 11afb34069ae98c1a769e3d62160a0dd2adc37ec
Author: Dodji Seketeli <dodji@redhat.com>
Date: Tue Jan 5 10:35:40 2010 +0100
Fix PR c++/40155
gcc/cp/ChangeLog:
c++/40155
* pt.c (unify_pack_expansion): In non-deduced contexts, re-use template
arguments that were previously deduced.
gcc/testsuite/ChangeLog:
c++/40155
* g++.dg/cpp0x/variadic-unify-2.C: New test.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d5342a1..d802971 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14071,8 +14071,15 @@ unify_pack_expansion (tree tparms, tree targs, tree packed_parms,
tree old_pack = TREE_VALUE (pack);
tree new_args = TREE_TYPE (pack);
int i, len = TREE_VEC_LENGTH (new_args);
+ int idx, level;
bool nondeduced_p = false;
+ /* By default keep the original deduced argument pack.
+ If necessary, more specific code is going to update the
+ resulting deduced argument later down in this function. */
+ template_parm_level_and_index (TREE_PURPOSE (pack), &level, &idx);
+ TMPL_ARG (targs, level, idx) = old_pack;
+
/* If NEW_ARGS contains any NULL_TREE entries, we didn't
actually deduce anything. */
for (i = 0; i < len && !nondeduced_p; ++i)
@@ -14103,10 +14110,6 @@ unify_pack_expansion (tree tparms, tree targs, tree packed_parms,
if (!old_pack)
{
tree result;
- int idx, level;
-
- template_parm_level_and_index (TREE_PURPOSE (pack), &level, &idx);
-
/* Build the deduced *_ARGUMENT_PACK. */
if (TREE_CODE (TREE_PURPOSE (pack)) == TEMPLATE_PARM_INDEX)
{
@@ -14130,12 +14133,7 @@ unify_pack_expansion (tree tparms, tree targs, tree packed_parms,
{
/* We only had the explicitly-provided arguments before, but
now we have a complete set of arguments. */
- int idx, level;
tree explicit_args = ARGUMENT_PACK_EXPLICIT_ARGS (old_pack);
- template_parm_level_and_index (TREE_PURPOSE (pack), &level, &idx);
-
- /* Keep the original deduced argument pack. */
- TMPL_ARG (targs, level, idx) = old_pack;
SET_ARGUMENT_PACK_ARGS (old_pack, new_args);
ARGUMENT_PACK_INCOMPLETE_P (old_pack) = 1;
@@ -14145,15 +14143,6 @@ unify_pack_expansion (tree tparms, tree targs, tree packed_parms,
new_args))
/* Inconsistent unification of this parameter pack. */
return 1;
- else
- {
- int idx, level;
-
- template_parm_level_and_index (TREE_PURPOSE (pack), &level, &idx);
-
- /* Keep the original deduced argument pack. */
- TMPL_ARG (targs, level, idx) = old_pack;
- }
}
return 0;
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic-unify-2.C b/gcc/testsuite/g++.dg/cpp0x/variadic-unify-2.C
new file mode 100644
index 0000000..80c9f5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic-unify-2.C
@@ -0,0 +1,14 @@
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin: PR c++/40155
+// { dg-options "-std=c++0x" }
+// { dg-do compile }
+
+template <typename T> struct identity
+{ typedef T type; };
+
+template <typename RT, typename... A>
+int forward_call(RT (*) (A...), typename identity<A>::type...);
+
+int g (double);
+
+int i = forward_call(&g, 0);
More information about the Gcc-patches
mailing list