Search

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

Closed
as Fixed Help for as Fixed

3
0
Sign in
to vote
Type: Bug
ID: 663884
Opened: 4/21/2011 7:58:43 AM
Access Restriction: Public
0
Workaround(s)
2
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.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010 SP1

What category (if any) best represents this feedback?

 

Steps to reproduce

//Compile this code:
enum enum_type { a, b, c };
//struct Bar { static const Bar a; }; //Compile with and without this line commented
template < typename U, U = U::a > struct Foo {};
template < typename U > void fun(Foo<U>) {}

int main(int argc, char* argv[])
{        
    Foo<enum_type> r;
    fun(r);
}

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

The sample code does not compile, with the following error:

c:\test\test.cpp(10): error C2784: 'void fun(Foo<U>)' : could not deduce template argument for 'Foo<U>' from 'Foo<U>'
         with
         [
             U=enum_type
         ]
         c:\users\robdavid\documents\visual studio 2010\projects\test\test\misi_found_template_error.cpp(5) : see declaration of 'fun'

However, uncommenting struct Bar, it compiles again, even though Bar is not used anywhere in the code.

Expected results

The sample code should compile with no errors (the warning about the non-standard usage of the enum scope is OK)
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 6/11/2011 at 7:26 PM
Hi:
    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;
    fun(r);
}

Thanks,
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.