[Codename Milan] MSVC rejects correct code with variadic templates - by Ivan Sorokin

Status : 


Sign in
to vote
ID 779496 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/19/2013 4:17:36 AM
Access Restriction Public


November CTP of MSVC rejects the following code:

template <typename ...T>
void f(void (* ...a)(T))

with error message

error C3520: 'T' : parameter pack must be expanded in this context
Sign in to post a comment.
Posted by Deon [MSFT] on 4/29/2014 at 12:30 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Jamie [MSFT] on 3/8/2013 at 4:23 PM
Hi Bengt,    
The syntax for parameter packs with function pointers can take a little getting used to, but the original example is actually legal (as is your own). Consider both examples expanded with types T1, T2, and T3:    
template <typename ...T>    
void f(void (* ...a)(T)) {}    
turns into    
void f(void (*a_1)(T1), void (*a_2)(T2), void (*a_3)(T3));    
template<typename... T>    
void f(void (*a)(T...)) {}    
turns into    
void f(void (*a)(T1, T2, T3));    
Another way to think about this is: a function pointer type itself contains several types, a return type and parameters. The entire function pointer type can be expanded as a parameter pack (the first example), or sub-elements of the function pointer types can be expanded (in your example, the parameters). All of these expansions can be further combined into more complicated expansions, which made testing this feature very "interesting".    
Jamie Eckman    
Visual C++ Team
Posted by Bengt Gustafsson on 2/27/2013 at 4:38 AM
I can't see that the example code should compile, the T should have ... after it inside the declaration. It is hard to understand what the intention of the declaration was, so I can't really show how it should be written. An example showng f which takes a function of "any" parameters is:

template<typename... T> f(void (*a)(T...)) {}

This could be what was intended...
Posted by Jonathan [MSFT] on 2/26/2013 at 4:09 PM
Hi: this issue has been fixed. The fix should show up in the next release of Visual C++.

Jonathan Caves
Visual C++ Compiler Team
Posted by Microsoft on 2/19/2013 at 11:29 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 2/19/2013 at 4:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)