Search

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

Closed

1
0
Sign in
to vote
Type: Bug
ID: 779496
Opened: 2/19/2013 4:17:36 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
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
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

Install November CTP on VS2012.

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

Product Language

English

Operating System

Windows 8

Operating System Language

English

Actual results

1.cpp(2) : error C3520: 'T' : parameter pack must be expanded in this context

Expected results

MSVC compiles this code.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft 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 Microsoft 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++.

Thanks
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)
Sign in to post a workaround.