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

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 782046 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 3/25/2013 9:47:22 AM
Access Restriction Public


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

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
    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(