Search

[Codename Milan] Delegating constructors not working with explicit constructors by Rutix

Closed
as Fixed Help for as Fixed

2
0
Sign in
to vote
Type: Bug
ID: 770526
Opened: 11/8/2012 1:50:57 PM
Access Restriction: Public
0
Workaround(s)
2
User(s) can reproduce this bug
The code:

struct X {
    explicit X(int n) : value(n) {}

    // error C2664: 'X::X(const X &)' : cannot convert parameter 2 from 'int' to 'const X &'
    // works without the explicit keyword in X(int) constructor
    X() : X(0) {}

    int value;
};

int main()
{
    X x;
}

This is not correct. It should compile fine and compiles in gcc-4.5.1 and other compilers supporting C++11.
Details (expand)

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

Visual Studio 2012

Steps to reproduce

struct X {
    explicit X(int n) : value(n) {}

    // error C2664: 'X::X(const X &)' : cannot convert parameter 2 from 'int' to 'const X &'
    // works without the explicit keyword in X(int) constructor
    X() : X(0) {}

    int value;
};

int main()
{
    X x;
}

Product Language

English

Operating System

Windows 7 SP1

Operating System Language

English

Actual results

error C2664: 'X::X(const X &)' : cannot convert parameter 2 from 'int' to 'const X &'

Expected results

Should compile without errors.
File Attachments
File Name Submitted By Submitted On File Size  
bug-repro.zip 11/11/2012 5 KB
bug-repro.zip 11/11/2012 5 KB
Sign in to post a comment.
Posted by Microsoft on 11/21/2012 at 10:08 AM
Hi:
    Thanks for reporting the issue.
    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 Microsoft on 11/12/2012 at 2:33 AM
Thanks for your update. 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 Rutix on 11/11/2012 at 1:15 PM
I attached a demo project. The project is basicly nothing more then the code I have above pasted in.
Posted by Microsoft on 11/9/2012 at 12:38 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. We are unable to reproduce the issue with the steps you provided.

Could you please give us a demo project to demonstrate this issue so that we can conduct further research?

Please submit this information to us within 4 business days. We look forward to hearing from you with this information.

Microsoft Visual Studio Connect Support Team
Posted by Microsoft on 11/8/2012 at 2:50 PM
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.