I'm fairly sure this should compile but it doesn't: --------------------- 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); ------------------------------------- The problem is the expansion typename identity<A>::type... which should wrap identity<An>::type around each element An of the template pack A. I'm not entirely familiar with all the rules for template packs yet, but I think that this should work, taking the examples in http://www.jot.fm/issues/issue_2008_02/article2/ into account. Best W.
Oh, should've said: g/x> /home/bangerth/bin/x86/gcc-mainline/bin/c++ -std=c++0x -c x.cc x.cc:9: error: invalid conversion from 'int (*)(double)' to 'int (*)()' x.cc:5: error: too many arguments to function 'int forward_call(RT (*)(A ...), typename identity<A>::type ...) [with RT = int, A = , typename identity<A>::type = A]' x.cc:9: error: at this point in file
FWIW, I think this code is valid. The A template parameter in "typename identity<A>::type..." is in a non-deduced context, so it's argument should not be deduced from there. The argument of A should be re-used from the deduction done using "RT (*) (A...)". And I think that's where the problem is. Once the compiler figured the second argument of forward_call is a non-deduced context, it fails to re-use the argument of A that was deduced in the context of the first argument of forward_call. I believe this should be flagged P1, even if it doesn't seem to be a regression.
(In reply to comment #2) > I believe this should be flagged P1, even if it doesn't seem to be a > regression. I'm obviously not impartial, but this is the sort of code that template packs are supposed to support, and forwarding calls is one of its main objectives. So I would definitely support getting this to work in 4.5... W.
Patch submitted to http://gcc.gnu.org/ml/gcc-patches/2010-01/msg00205.html
Subject: Bug 40155 Author: dodji Date: Thu Jan 7 19:21:46 2010 New Revision: 155705 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155705 Log: 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. Added: trunk/gcc/testsuite/g++.dg/cpp0x/variadic-unify-2.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
Fixed in 4.5