Search

[C++] Reference default argument falsely converted to pointer on instantiation of more than 2 explicit specializations by CodingCat

Closed
as Fixed Help for as Fixed

2
0
Sign in
to vote
Type: Bug
ID: 718578
Opened: 1/14/2012 9:36:52 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
The VC++ 2010 compiler falsely converts default arguments of reference types to default arguments of pointer types when there are more than 2 explicit specializations of the corresponding function template and both are used in the same compilation unit. See details for example code.
Details (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

int& some_global_int()
{
    static int num;
    return num;
}

template <class Type>
int fun(int &i = some_global_int()) { return 6; }

template <>
int fun<int>(int &i) { return 2; }

template <>
int fun<float>(int &i) { return 3; }

int main()
{
    fun<int>();
    fun<float>(); // error C2440: 'default argument' : cannot convert from 'int *' to 'int &'
    return 0;
}

Product Language

English

Operating System

Windows 7

Operating System Language

German

Actual results

error C2440: 'default argument' : cannot convert from 'int *' to 'int &'

Expected results

Should compile just fine.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 1/16/2012 at 12:30 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++ Team
Posted by MS-Moderator07 [Feedback Moderator] on 1/15/2012 at 7:05 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 MS-Moderator01 on 1/14/2012 at 9:43 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.