Search

[c++] Compiler fails to deduce template parameter. by Cory Nelson

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 619198
Opened: 11/4/2010 1:25:24 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
The attached reproduction code uses tags and template argument deduction to pull base classes out of a derived class. It is 100% legal C++, and compiles fine in GCC (tested with v4.5.1).

The first use of the "get" function works just as expected, but for some reason the second produces two identical C2784 errors, followed by a single C2782 error. These errors are incorrect -- the template arguments are in no way ambiguous.

Interestingly enough, IntelliSense is able to deduce the types correctly.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

struct base1 {};
struct base2 {};

struct tag1 {};
struct tag2 {};

template<typename Base, typename Tag>
struct tagged {};

struct test : tagged<base1, tag1>, tagged<base2, tag2> {};

template<typename Tag, typename Base>
inline tagged<Base, Tag>& get(tagged<Base, Tag> &o) { return o; }

int main()
{
    test t;

    get<tag1>(t); // works.
    get<tag2>(t); // fails to compile -- template parameter 'Base' is ambiguous.

    return 0;
}

Product Language

English

Operating System

Windows 7

Operating System Language

English (US)

Actual results

the compiler errors out

Expected results

this standard-compliant code should compile without error.
File Attachments
File Name Submitted By Submitted On File Size  
cxxtest.cpp 11/4/2010 453 bytes
Sign in to post a comment.
Posted by Cory Nelson on 2/6/2011 at 5:49 AM
Will this fix be in 2010 SP1, or will we have to wait for whatever is next?
Posted by Microsoft on 11/4/2010 at 2:09 AM
Thanks for your feedback. We are routing 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.
Sign in to post a workaround.