Consider the following code, compiled with the latest gcc built from sources,
with the -std=c++0x flag:

#include <iostream>
struct S
{
    S() {}
    S(S &s) { std::cout << "L-value ref" << std::endl; }
    S(S &&s) { std::cout << "R-value ref" << std::endl; }
};

S source() { static S s; return s; }

int main()
{
    std::cout << "here 1 \n";
    S s;
    std::cout << "here 2 \n";
    S t(s);
    std::cout << "here 3 \n";
    S u(source()); // ERROR HERE
}

For me, this prints:

here 1
here 2
L-value ref
here 3
L-value ref

It should print:

here 1
here 2
L-value ref
here 3
R-value ref

An rvalue should under no circumstance bind to a non-const lvalue reference.


-- 
           Summary: rvalue erroneously binding to non-const lvalue reference
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: eric dot niebler at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34700

Reply via email to