Home Dashboard Directory Help

VC10: weird template deduction error with non-type default template argument by Dávid Róbert


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 663884
Opened: 4/21/2011 7:58:43 AM
Access Restriction: Public
User(s) can reproduce this bug


There is a weird template deduction error in VC10 SP1 - the sample code is not compiling.

However, if I uncomment the unused struct with a member that has the same name as the default value of the template argument, it compiles.

See steps to reproduce for more.
Sign in to post a comment.
Posted by Microsoft on 6/11/2011 at 7:26 PM
    A fix for this issue has been checked into the compiler sources.
    The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Compiler Team
Posted by Dávid Róbert on 5/6/2011 at 3:06 AM
The workaround not really solves the issue - we wanted to create a template that detects if an enum type has a given value. (Our project has lots of enums having a Count value - wanted to detect that.)

However, uncommenting struct Bar in the sample code looks like a viable solution.
Posted by Microsoft on 5/5/2011 at 2:56 PM
Hello David,

Thank you for reporting this bug. This is a bug in the compiler where we parse the default non-type template argument list for templates. We will consider fixing this in a future release. In the meantime, please accept this workaround if possible. Apologize for any inconvinience.
enum enum_type { a, b, c };
//struct Bar { static const Bar a; }; //Compile with and without this line commented
template < typename U, U T> // = U::a>
struct Foo {};
template < typename U > void fun( Foo<U, enum_type::a> f ) {}

int main(int argc, char* argv[])
    Foo<enum_type, enum_type::a> r;

Ulzii Luvsanbat
Windows C++ Team
Posted by Microsoft on 4/21/2011 at 10:32 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 4/21/2011 at 8:14 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.