Search

VC11 does not compile valid code using rvalue references by Xentrax [Vyacheslav Lanovets]

Closed
as Deferred Help for as Deferred

1
0
Sign in
to vote
Type: Bug
ID: 767153
Opened: 10/12/2012 1:32:46 AM
Access Restriction: Public
1
Workaround(s)
0
User(s) can reproduce this bug
VC++ 17.00.50727.1 for x86 does not compile valid C++ code using rvalue references.

According to guys om comp.lang.c++.moderated this is a bug in VC compiler:
https://groups.google.com/d/msg/comp.lang.c++.moderated/HjcLTUvohBk/t5IjszlaG1wJ

Details (expand)

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

Visual Studio 2012

Steps to reproduce

Try to compile the following
==============================
#include <utility>

struct A
{
        int y;
};
A getA()
{
        return A();
}
void fi(int&& )
{
}
void fa(A&& )
{
}

int main()
{
        fi(std::move(getA()).y); // compiles
        fi(A().y); // 1 -compiles
        fa(A()); // compiles
        fa(getA()); // compiles

        fi(getA().y); // 2 - does not compile. Why?

        return 0;
}

Product Language

English

Operating System

Windows 7 SP1

Operating System Language

English

Actual results

x.cpp(25) : error C2664: 'fi' : cannot convert parameter 1 from 'int' to 'int &&'
        You cannot bind an lvalue to an rvalue reference

Expected results

successful compile
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 10/12/2012 at 2:01 AM
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 10/12/2012 at 1: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.
Posted by Xentrax [Vyacheslav Lanovets] on 10/12/2012 at 1:34 AM
std::move does the trick:

fi(std::move(getA()).y);