Home Dashboard Directory Help
Search

Conversion operators/constructors do not work for arguments passed by reference by mnvm


Status: 

Closed
 as By Design Help for as By Design


1
0
Sign in
to vote
Type: Bug
ID: 782046
Opened: 3/25/2013 9:47:22 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Conversion operators/constructors do not work for arguments passed by reference.

Details
Sign in to post a comment.
Posted by mnvm on 3/27/2013 at 11:30 AM
The extension fixes a bug in the standard. There is no reason to prevent a temporary from being passed by reference. This useless limitation of the standard results only in more lines of code and more bugs. Microsoft should push the extension to the standard.

The extension is not reported as legacy by the compiler. Why should conversions work only for const references? This is a bug.
Posted by Microsoft on 3/26/2013 at 11:41 AM
Hi:
    Thanks for reporting the issue.
    This is by design. According to the C++ standard, a temporary can't bind to non-const reference. In your code, the conversion from 'A' to 'B &' has a temporary B (the result of 'A::operator B') which can't bind to 'B &'.
    Note that VC has an extension to allow the binding in some cases, but it is for legacy code and doesn't apply here. Conformant code should not rely on the extension.

Xiang Fan
Visual C++ Team
Posted by Microsoft on 3/25/2013 at 8:54 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 3/25/2013 at 9:50 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.