From c8f4e43a8c80cc3262b91d969a5420da62dae306 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Thu, 7 Jan 2010 19:21:46 +0000 Subject: re PR c++/40155 ([c++0x] variadic template pack problem) 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. From-SVN: r155705 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 25 +++++++------------------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/variadic-unify-2.C | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/variadic-unify-2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 158e80d..07a3486 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2010-01-07 Dodji Seketeli + + c++/40155 + * pt.c (unify_pack_expansion): In non-deduced contexts, re-use template + arguments that were previously deduced. + 2010-01-05 Jason Merrill * pt.c (unify_pack_expansion): Handle deduction from init-list. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d814736..f27b931 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14074,8 +14074,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) @@ -14106,10 +14113,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) { @@ -14133,12 +14136,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; @@ -14148,15 +14146,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/ChangeLog b/gcc/testsuite/ChangeLog index d68e6e9..f222396 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-01-07 Dodji Seketeli + + c++/40155 + * g++.dg/cpp0x/variadic-unify-2.C: New test. + 2010-01-07 Jakub Jelinek PR tree-optimization/42625 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 +// Origin: PR c++/40155 +// { dg-options "-std=c++0x" } +// { dg-do compile } + +template struct identity +{ typedef T type; }; + +template +int forward_call(RT (*) (A...), typename identity::type...); + +int g (double); + +int i = forward_call(&g, 0); -- cgit v1.1