VC11: non-const lvalue reference incorrectly binds to rvalue - by jhansw

Status : 

  Deferred<br /><br />
		The product team has reviewed this issue and has deferred it for consideration at a later time.<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 775818 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 1/4/2013 10:07:28 AM
Access Restriction Public


struct A

A f() { return A() };

int main()
    A& a = func();

This compiles, when it shouldn't. Non-const l-value references must bind to lvalues. The value category of a function call is a prvalue.

Sign in to post a comment.
Posted by Cassio Neri on 12/28/2013 at 6:52 AM
IMHO this is a quite serious bug which create others. For instance, the code in

doesn't compile on gcc because std::swap(T& x, T& y) takes lvalues and test[0] and test[1] are rvalues (so std::swap(test[0], test[1]) is illegal).

As explained in Hans Passant's comment to Victor Nicollet's answer VS (2013 Nov CTP) accepts the illegal code and produces an unexpected result at runtime.
Posted by UnitUniverse on 2/16/2013 at 7:16 AM
Stop yelling and just wait for months. There are many things they have to consider and handle.
Posted by Gene Bushuyev on 2/14/2013 at 10:56 AM
This is very irresponsible answer from Microsoft. It's one of the severe bugs that should have been fixed a decade ago. It also should be trivial to fix it. Yes, it will break the buggy code, which is good, people need to fix the bugs like this in their programs.
Posted by UnitUniverse on 2/2/2013 at 6:51 AM
@Karl Niu

I have investigated this issue and found that it WAS(and should have not kept for now. i talk about this latter) by design in version from vc6.0(at least) to vs2008 c++ compiler. There is no c++0x/11 standard specifics in these version, so there is no way to mark and detect the rvalue in language level. The solution of those compiler is allowing unsafe but usable r2l-lvalue-reference binding, As the extension of C++98 (As i know, it should be expose Warning C4239 only if you had configged your project at highest warning level). After that, the release 2010 (vc10) has implimented the rvalue-references(Type &&) and no longer has such limitation of C++98. i remember that there is a document in msdn vcblog said that the VS2010 sp1 has disabled the r2l-lvalue binding to solve a security-issue(
"The difference between what I call "rvalue references v1" and "rvalue references v2" is that v1 allowed rvalue references to bind to lvalues, while v2 forbids this. N2844 "Fixing a Safety Problem with Rvalue References" describes the reasons for this change."), which i am sure that it have relation to this bug report. and now that issue just re-open in vs2012. I think you might have considered that old style rv-binding, or any vc-compiler project manager decided to use that old style, or some one fixed another compiler issue by edit the older released sources from vs2010sp1(from 2010 WITHOUT sp1 or even from ver. 2008) and then committed them into the vs2012 compiler project.
What i supposed is: If the compiler-team still worries about the compatibilities issues for disabling the r2l-lvalue referense binding: If the vs2010sp1 can handle that without 4239 extension, the vs2012 should also be able to handle that.
Posted by Microsoft on 1/25/2013 at 5:09 PM
Hi jhansw,

Thank you for taking the time to provide your feedback. After reviewing your reported issue, in the context of all the issues reported to us, we have decided not to take any action on this feedback at this time. However, we will re-consider our decision for a future release.

If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to or call 1-800-MICROSOFT for assistance.
For Microsoft premier customers, please contact your administrator, your Technical Account Manager, or your Microsoft premier account representative.

Karl Niu
VC++ Team
Posted by Microsoft on 1/6/2013 at 11:47 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 1/4/2013 at 10:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(